From 54a19bcde2c599cd18484e03ca1bb314410c317c Mon Sep 17 00:00:00 2001 From: Milky Raven Date: Fri, 4 Nov 2022 15:48:02 +0100 Subject: [PATCH 1/9] new archives created --- Project/views/catalogue.hbs | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Project/views/catalogue.hbs diff --git a/Project/views/catalogue.hbs b/Project/views/catalogue.hbs new file mode 100644 index 0000000..e69de29 From acd015f771ec11d18a858c83789cc085f88183bf Mon Sep 17 00:00:00 2001 From: Milky Raven Date: Fri, 4 Nov 2022 15:48:14 +0100 Subject: [PATCH 2/9] new documents --- Project/models/Comics.model.js | 12 ++++++++++++ Project/models/Reviews.model.js | 0 Project/models/ShoppingCart.model.js | 0 Project/views/product-details.hbs | 0 4 files changed, 12 insertions(+) create mode 100644 Project/models/Comics.model.js create mode 100644 Project/models/Reviews.model.js create mode 100644 Project/models/ShoppingCart.model.js create mode 100644 Project/views/product-details.hbs diff --git a/Project/models/Comics.model.js b/Project/models/Comics.model.js new file mode 100644 index 0000000..90e71bd --- /dev/null +++ b/Project/models/Comics.model.js @@ -0,0 +1,12 @@ +const { Schema, model } = require("mongoose"); + +const comicSchema = new Schema( + { + title: String, + timestamps: true, + } +); + +const User = model("User", userSchema); + +module.exports = User; diff --git a/Project/models/Reviews.model.js b/Project/models/Reviews.model.js new file mode 100644 index 0000000..e69de29 diff --git a/Project/models/ShoppingCart.model.js b/Project/models/ShoppingCart.model.js new file mode 100644 index 0000000..e69de29 diff --git a/Project/views/product-details.hbs b/Project/views/product-details.hbs new file mode 100644 index 0000000..e69de29 From 09600a3d63df4bc5e31b66f346e78bb8c4241568 Mon Sep 17 00:00:00 2001 From: Milky Raven Date: Fri, 4 Nov 2022 15:51:08 +0100 Subject: [PATCH 3/9] new documents --- Project/models/Comics.model.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Project/models/Comics.model.js b/Project/models/Comics.model.js index 90e71bd..da58365 100644 --- a/Project/models/Comics.model.js +++ b/Project/models/Comics.model.js @@ -3,6 +3,7 @@ const { Schema, model } = require("mongoose"); const comicSchema = new Schema( { title: String, + name: String, timestamps: true, } ); From 563b54252e7dc4f190b32fe7ed9cf4017d031a7e Mon Sep 17 00:00:00 2001 From: Milky Raven Date: Fri, 4 Nov 2022 15:57:41 +0100 Subject: [PATCH 4/9] test --- Project/models/Comics.model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/models/Comics.model.js b/Project/models/Comics.model.js index da58365..24dbcfc 100644 --- a/Project/models/Comics.model.js +++ b/Project/models/Comics.model.js @@ -8,6 +8,6 @@ const comicSchema = new Schema( } ); -const User = model("User", userSchema); +const User = model("User", comicSchema); module.exports = User; From 1d957e745a90e3f199a935dfa33da4d54154d06d Mon Sep 17 00:00:00 2001 From: Milky Raven Date: Fri, 4 Nov 2022 16:18:48 +0100 Subject: [PATCH 5/9] models created --- Project/models/Comics.model.js | 15 +++++++++++---- Project/models/Reviews.model.js | 15 +++++++++++++++ Project/models/ShoppingCart.model.js | 15 +++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/Project/models/Comics.model.js b/Project/models/Comics.model.js index 24dbcfc..2970d6b 100644 --- a/Project/models/Comics.model.js +++ b/Project/models/Comics.model.js @@ -3,11 +3,18 @@ const { Schema, model } = require("mongoose"); const comicSchema = new Schema( { title: String, - name: String, - timestamps: true, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number } ); -const User = model("User", comicSchema); +const Comic = model("Comic", comicSchema); -module.exports = User; +module.exports = Comic; diff --git a/Project/models/Reviews.model.js b/Project/models/Reviews.model.js index e69de29..8f8a87c 100644 --- a/Project/models/Reviews.model.js +++ b/Project/models/Reviews.model.js @@ -0,0 +1,15 @@ +const { Schema, model } = require("mongoose"); + +const reviewSchema = new Schema( + { + title: String, + userId: {type: Schema.Types.ObjectId, ref: 'User'}, + comicId: {type: Schema.Types.ObjectId, ref: 'Comic'}, + content: String, + rating: Number + } +); + +const Review = model("Review", reviewSchema); + +module.exports = Review; diff --git a/Project/models/ShoppingCart.model.js b/Project/models/ShoppingCart.model.js index e69de29..b5fc140 100644 --- a/Project/models/ShoppingCart.model.js +++ b/Project/models/ShoppingCart.model.js @@ -0,0 +1,15 @@ +//THIS DOCUMENTS NEEDS TO BE CHECKED, PROBABLY WILL GIVE ERRORS- TEST +const { Schema, model } = require("mongoose"); + +const shoppingCartSchema = new Schema( + { + userId: {type: Schema.Types.ObjectId, ref: 'User'}, + productIds: [{type: Schema.Types.ObjectId, ref: 'Comic'}], + productQuantity: Number, + totalPrice: Number + } +); + +const shoppingCart = model("shoppingCart", shoppingCartSchema); + +module.exports = shoppingCart; From 57154ce5c1e906333a92b43206248d3573402469 Mon Sep 17 00:00:00 2001 From: Yaron Peres Date: Fri, 4 Nov 2022 16:34:16 +0100 Subject: [PATCH 6/9] first routes --- Project/routes/index.routes.js | 9 +++++++++ Project/views/catalogue.hbs | 1 + Project/views/index.hbs | 2 +- Project/views/layout.hbs | 4 ++++ Project/views/product-details.hbs | 1 + 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Project/routes/index.routes.js b/Project/routes/index.routes.js index f538ffe..27ca2a2 100644 --- a/Project/routes/index.routes.js +++ b/Project/routes/index.routes.js @@ -5,5 +5,14 @@ const router = express.Router(); router.get("/", (req, res, next) => { res.render("index"); }); +// ------------------------ catalogue Routes ------------------------ +router.get("/catalogue", (req, res, next) => { + res.render("catalogue") +}) +// --------------------- Product details Routes ------------------------ +router.get("/product-details", (req, res, next) => { + res.render("product-details") +}) + module.exports = router; diff --git a/Project/views/catalogue.hbs b/Project/views/catalogue.hbs index e69de29..ef2d29f 100644 --- a/Project/views/catalogue.hbs +++ b/Project/views/catalogue.hbs @@ -0,0 +1 @@ +

catalogue

\ No newline at end of file diff --git a/Project/views/index.hbs b/Project/views/index.hbs index 2c1bb13..d85aa20 100644 --- a/Project/views/index.hbs +++ b/Project/views/index.hbs @@ -1,2 +1,2 @@

{{appTitle}} šŸš€

-

Welcome Ironhacker!

\ No newline at end of file +

Welcome Ironhacker!

diff --git a/Project/views/layout.hbs b/Project/views/layout.hbs index 06fce19..6deead7 100644 --- a/Project/views/layout.hbs +++ b/Project/views/layout.hbs @@ -9,6 +9,10 @@ +Catalogue +Product Details +Home + {{{body}}} diff --git a/Project/views/product-details.hbs b/Project/views/product-details.hbs index e69de29..a942fa0 100644 --- a/Project/views/product-details.hbs +++ b/Project/views/product-details.hbs @@ -0,0 +1 @@ +

Product Details

\ No newline at end of file From f9f942bd26b8ba8fe64564da362fadc5d331cc59 Mon Sep 17 00:00:00 2001 From: Milky Raven Date: Fri, 4 Nov 2022 16:49:13 +0100 Subject: [PATCH 7/9] working on seeds --- Project/bin/seeds.js | 115 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/Project/bin/seeds.js b/Project/bin/seeds.js index 608043c..3f1fb3a 100644 --- a/Project/bin/seeds.js +++ b/Project/bin/seeds.js @@ -1,8 +1,121 @@ const mongoose = require("mongoose") // Require the models, Example: (-- const Book = require("../models/Book.model") --) +const Comic = require("../models/Comics.model") -const MONGO_URI = "mongodb://localhost:27017/project2" +const MONGO_URI = "mongodb://localhost:27017/vintageComicShop" + +const comic = [ + { + title: "The Batman Meets Doctor Death", + img: "https://files1.comics.org//img/gcd/covers_by_id/5/w400/5137.jpg?-3164861915678165786", + author: "Book Kane", + comicSeries: "Detective Comics", + year: 1939, + condition: "Used", + synopsis: "Dr. Death plans to use his new invention of a poisonous pollen extract on any wealthy person who refuses to pay him tribute.", + price: 16.99, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: 4 + }, + + { + title: "Les Cigares du Pharaon", + img: "https://files1.comics.org//img/gcd/covers_by_id/1493/w400/1493274.jpg?1117383809191476521", + author: "HergƩ", + comicSeries: "Les Aventures de Tintin", + year: 1987, + condition: "Good", + synopsis: "Holidaying on a Mediterranean cruise ship, Tintin and his dog Snowy meet wealthy film producer Rastapopoulos and eccentric Egyptologist Sophocles Sarcophagus", + price: 9.99, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: 6}, + + { + title: "Action Comics No. 40", + img: "https://files1.comics.org//img/gcd/covers_by_id/0/w400/565.jpg?-6831418524261450474", + author: "Fred Ray", + comicSeries: "Action Comics", + year: "1938" , + condition: "Used", + synopsis: "", + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + }, + { + title: String, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + }, + { + title: String, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + }, + { + title: String, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + }, + { + title: String, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + }, + { + title: String, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + }, + { + title: String, + img: String, + author: String, + comicSeries: String, + year: Number, + condition: String, + synopsis: String, + price: Number, + reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + quantity: Number + } +] const createSeeds = async function () { From 8482aee34dabb99e124ff89326c51fdbfa3f2dd1 Mon Sep 17 00:00:00 2001 From: Yaron Peres Date: Fri, 4 Nov 2022 17:50:48 +0100 Subject: [PATCH 8/9] comicsseeds --- Project/bin/seeds.js | 183 +++++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 83 deletions(-) diff --git a/Project/bin/seeds.js b/Project/bin/seeds.js index 3f1fb3a..6c7c439 100644 --- a/Project/bin/seeds.js +++ b/Project/bin/seeds.js @@ -15,7 +15,7 @@ const comic = [ condition: "Used", synopsis: "Dr. Death plans to use his new invention of a poisonous pollen extract on any wealthy person who refuses to pay him tribute.", price: 16.99, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], + reviewIds: [], quantity: 4 }, @@ -28,93 +28,106 @@ const comic = [ condition: "Good", synopsis: "Holidaying on a Mediterranean cruise ship, Tintin and his dog Snowy meet wealthy film producer Rastapopoulos and eccentric Egyptologist Sophocles Sarcophagus", price: 9.99, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: 6}, + reviewIds: [], + quantity: 6 + }, - { + { title: "Action Comics No. 40", img: "https://files1.comics.org//img/gcd/covers_by_id/0/w400/565.jpg?-6831418524261450474", author: "Fred Ray", comicSeries: "Action Comics", year: "1938" , condition: "Used", - synopsis: "", - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - }, - { - title: String, - img: String, - author: String, - comicSeries: String, - year: Number, - condition: String, - synopsis: String, - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - }, - { - title: String, - img: String, - author: String, - comicSeries: String, - year: Number, - condition: String, - synopsis: String, - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - }, - { - title: String, - img: String, - author: String, - comicSeries: String, - year: Number, - condition: String, - synopsis: String, - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - }, - { - title: String, - img: String, - author: String, - comicSeries: String, - year: Number, - condition: String, - synopsis: String, - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - }, - { - title: String, - img: String, - author: String, - comicSeries: String, - year: Number, - condition: String, - synopsis: String, - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - }, - { - title: String, - img: String, - author: String, - comicSeries: String, - year: Number, - condition: String, - synopsis: String, - price: Number, - reviewIds: [{ type: Schema.Types.ObjectId, ref: 'Review'}], - quantity: Number - } + synopsis: "A millionaire agrees to pay $100,000 to charity if Superman helps to straighten out his wayward daughter who spends money as if it were water as various gambling establishments. Only when an emergency arises does the girl see herself in a different vein.", + price: 199.9, + reviewIds: [], + quantity: 2 + }, + { + title: "Mafalda", + img: "https://files1.comics.org//img/gcd/covers_by_id/1312/w400/1312954.jpg?7950182444208753492", + author: "Quino", + comicSeries: "Mafalda", + year: 1966, + condition: "Good", + synopsis: "Mafalda is a girl who faces reality with the ingenuity and tenderness typical of childhood.", + price: 22.99, + reviewIds: [], + quantity: 2 + }, + { + title: "Misantropolis", + img: "https://files1.comics.org//img/gcd/covers_by_id/1012/w400/1012879.jpg?3921397601305097350", + author: "Tove Jansson", + comicSeries: "Mummintroll", + year: 1995, + condition: "Very Good", + synopsis: "The main protagonist, the little boy of the family, is interested in and excited about everything he sees and finds, always trying to be good, but sometimes getting into trouble while doing so; he is very brave and always finds a way to make his friends happy.", + price: 14.99, + reviewIds: [], + quantity: 3 + }, + { + title: "Action Comics No. 27", + img: "https://files1.comics.org//img/gcd/covers_by_id/0/w400/552.jpg?4303249213407754409", + author: "Paul Cassidy", + comicSeries: "Action Comics", + year: 1940, + condition: "Used", + synopsis: "Clark arrives for a date with Lois, who is making a donation to the Brentwood Rehabilitation Home. Clark tells her that the place is more interested in money than their young charges. Lois decides they should visit the home so that she can disprove Clark. After a pleasant visit, Lois and Clark are stopped by a charge, Davey Merrill, who cut his hands climbing the wall just to ask for something to eat. Once they feed him, he tells them all about the horrible conditions at the home", + price: 169.99, + reviewIds: [], + quantity: 1 + }, + { + title: "Action Comics No. 150", + img: "https://files1.comics.org//img/gcd/covers_by_id/1138/w400/1138923.jpg?7824686344579582815", + author: "Wayne Boring", + comicSeries: "Action Comics", + year: 1950, + condition: "Used", + synopsis: 'Mr. Mxyztplk teams with the Prankster and Lex Luthor to humiliate Superman by making "plastic proxies" (androids) which make it appear as if Lois has jilted Superman for Mxyztplk, make it seem that Superman has falsely accusing Luthor, and make Superman look like the victim of the pranks of the Prankster. But just as the public begins to wonder why they ever admired him, Superman turns the tables on the trio.', + price: 99.9, + reviewIds: [], + quantity: 3 + }, + { + title: "The Rose of Versailles Vol.1", + img: "https://files1.comics.org//img/gcd/covers_by_id/1379/w400/1379263.jpg?-6745954624512040830", + author: "Riyoko Ikea", + comicSeries: "The Rose of Versailles", + year: 1981, + condition: "Used", + synopsis: "Oscar Francois de Jarjeyes is a young noblewoman raised as a son by her father. As commander of Marie Antoinette's palace guard, Oscar is brought face-to-face with the luxury of King Louis XVI's court at Versailles. Joined by her servant Andre, Oscar is privy to the intrigue and deceit of France's last great royal regime.", + price: 6.99, + reviewIds: [], + quantity: 7 + }, + { + title: "NausicaƤ of the Valley of Wind #1", + img: "NausicaƤ of the Valley of Wind #1", + author: "Hayao Miyazaki", + comicSeries: "NausicaƤ of the Valley of Wind", + year: 1988, + condition: "Very Good", + synopsis: "Taking place in a post-nuclear futuristic world, the film tells the story of NausicaƤ (Shimamoto), the young teenage princess of the Valley of the Wind. She becomes embroiled in a struggle with Tolmekia, a kingdom that tries to use an ancient weapon to eradicate a jungle full of giant mutant insects.", + price: 34.99, + reviewIds: [], + quantity: 1 + }, + { + title: "Action Comics No. 3", + img: "https://files1.comics.org//img/gcd/covers_by_id/2/w400/2465.jpg?-4414093043624628871", + author: "Bill Finger", + comicSeries: "Batman", + year: 1940, + condition: "Used", + synopsis: "The Caped Crusaders must stop the likes of the Puppet Master, who has set his sights on stealing the Voss Rifle, the Army's newly developed secret gun. But to do it, Batman must overcome the effects of having come under the hypnotic influence of his foe.", + price: 89.99, + reviewIds: [], + quantity: 9 + } ] @@ -123,10 +136,14 @@ const createSeeds = async function () { const connect = await mongoose.connect(MONGO_URI) console.log(`Connected to database: ${connect.connections[0].name}`) - // Clear DB, Example: (-- const deleteAll = await Book.deleteMany() --) - // console.log("Db clean") + const deleteAll = await Comic.deleteMany() + console.log("Db clean") + + const createAll = await Comic.create(comic) + console.log("comics created") const dbClose = await mongoose.connection.close() + console.log("Seeds created") } catch (err) { console.log(`Error creating the seeds: ${err}`) From 0ab6c9c91de6ff566eb74df8feb2a6a497b17dc8 Mon Sep 17 00:00:00 2001 From: Yaron Peres Date: Sat, 5 Nov 2022 11:19:33 +0100 Subject: [PATCH 9/9] reviews seeds, users and comics are commented to not affect the reviews seed --- Project/bin/seeds.js | 66 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/Project/bin/seeds.js b/Project/bin/seeds.js index 6c7c439..8ebfe87 100644 --- a/Project/bin/seeds.js +++ b/Project/bin/seeds.js @@ -2,6 +2,8 @@ const mongoose = require("mongoose") // Require the models, Example: (-- const Book = require("../models/Book.model") --) const Comic = require("../models/Comics.model") +const User = require("../models/User.model") +const Review = require("../models/Reviews.model") const MONGO_URI = "mongodb://localhost:27017/vintageComicShop" @@ -130,17 +132,73 @@ const comic = [ } ] +const users = [ + { + username: "yaron1", + email: "yaron1@gmail.com", + password: "1234", + }, + { + username: "carol", + email: "carol@gmail.com", + password: "1234", + }, + { + username: "carlas", + email: "carlas@gmail.com", + password: "1234", + } +] +const reviews = [ + { + title: "Very good service", + userId: "6366346c4ba4c2af26cefabb", + comicId: "6366346c4ba4c2af26cefaab", + content: "Very good service from the store, fast delivery and the comic is in a very good condition as well", + rating: 5 + }, + { + title: "Nice quality", + userId: "6366346c4ba4c2af26cefabc", + comicId: "6366346c4ba4c2af26cefaad", + content: "The comic arrived in a good quality, service was ok", + rating: 4 + }, + { + title: "Service is good But the comic is too vintage", + userId: "6366346c4ba4c2af26cefabd", + comicId: "6366346c4ba4c2af26cefaae", + content: "The comic arrived in a bad condition ive expected for better condition", + rating: 3 + } +] + const createSeeds = async function () { try { const connect = await mongoose.connect(MONGO_URI) console.log(`Connected to database: ${connect.connections[0].name}`) +//---------------------comics seeds -------------- + //const deleteAll = await Comic.deleteMany() + //console.log("Comic Db clean") + + //const createAll = await Comic.create(comic) + //console.log("comics created") +//---------------------comics seeds -------------- +//---------------------users seeds -------------- + //const deleteAllUser = await User.deleteMany() + //console.log("User Db clean") - const deleteAll = await Comic.deleteMany() - console.log("Db clean") + //const createAllUser = await User.create(users) + //console.log("users created") +//---------------------users seeds -------------- +//---------------------review seeds -------------- + const deleteAllreview = await Review.deleteMany() + console.log("reviews Db clean") - const createAll = await Comic.create(comic) - console.log("comics created") + const createAllreview = await Review.create(reviews) + console.log("reviews created") +//---------------------review seeds -------------- const dbClose = await mongoose.connection.close()