diff --git a/Project/bin/seeds.js b/Project/bin/seeds.js index 608043c..8ebfe87 100644 --- a/Project/bin/seeds.js +++ b/Project/bin/seeds.js @@ -1,19 +1,207 @@ 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/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: [], + 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: [], + 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: "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 + } +] + +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 createAllUser = await User.create(users) + //console.log("users created") +//---------------------users seeds -------------- +//---------------------review seeds -------------- + const deleteAllreview = await Review.deleteMany() + console.log("reviews Db clean") - // Clear DB, Example: (-- const deleteAll = await Book.deleteMany() --) - // console.log("Db clean") + const createAllreview = await Review.create(reviews) + console.log("reviews created") +//---------------------review seeds -------------- const dbClose = await mongoose.connection.close() + console.log("Seeds created") } catch (err) { console.log(`Error creating the seeds: ${err}`) diff --git a/Project/models/Comics.model.js b/Project/models/Comics.model.js new file mode 100644 index 0000000..2970d6b --- /dev/null +++ b/Project/models/Comics.model.js @@ -0,0 +1,20 @@ +const { Schema, model } = require("mongoose"); + +const comicSchema = new Schema( + { + 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 Comic = model("Comic", comicSchema); + +module.exports = Comic; diff --git a/Project/models/Reviews.model.js b/Project/models/Reviews.model.js new file mode 100644 index 0000000..8f8a87c --- /dev/null +++ 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 new file mode 100644 index 0000000..b5fc140 --- /dev/null +++ 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; 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 new file mode 100644 index 0000000..ef2d29f --- /dev/null +++ b/Project/views/catalogue.hbs @@ -0,0 +1 @@ +
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 new file mode 100644 index 0000000..a942fa0 --- /dev/null +++ b/Project/views/product-details.hbs @@ -0,0 +1 @@ +