diff --git a/api/retrieve.js b/api/retrieve.js index e779509..95fbdaf 100644 --- a/api/retrieve.js +++ b/api/retrieve.js @@ -9,11 +9,19 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", { const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); const Wine = require(path.join(__dirname + "/../schemas/Wine")); const Highscore = require(path.join(__dirname + "/../schemas/Highscore")); +const PreLotteryWine = require(path.join( + __dirname + "/../schemas/PreLotteryWine" +)); router.use((req, res, next) => { next(); }); +router.route("/wines/prelottery").get(async (req, res) => { + let wines = await PreLotteryWine.find(); + res.json(wines); +}); + router.route("/purchase/statistics").get(async (req, res) => { let purchases = await Purchase.find() .populate("wines") diff --git a/api/update.js b/api/update.js index d9012f0..b4961c9 100644 --- a/api/update.js +++ b/api/update.js @@ -8,17 +8,44 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", { const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); const Wine = require(path.join(__dirname + "/../schemas/Wine")); +const PreLotteryWine = require(path.join( + __dirname + "/../schemas/PreLotteryWine" +)); const Highscore = require(path.join(__dirname + "/../schemas/Highscore")); router.use((req, res, next) => { next(); }); +router.route("/log/wines").post(async (req, res) => { + if (!req.isAuthenticated()) { + res.send(false); + return; + } + console.log(req.body); + const wines = req.body; + console.log(wines); + for (let i = 0; i < wines.length; i++) { + let wine = wines[i]; + let newWonWine = new PreLotteryWine({ + name: wine.name, + vivinoLink: wine.vivinoLink, + rating: wine.rating + }); + await newWonWine.save(); + } + + res.send(true); +}); + router.route("/log").post(async (req, res) => { if (!req.isAuthenticated()) { res.send(false); return; } + + await PreLotteryWine.deleteMany(); + const purchaseBody = req.body.purchase; const winnersBody = req.body.winners; @@ -35,7 +62,7 @@ router.route("/log").post(async (req, res) => { let wonWine = await Wine.findOne({ name: currentWinner.wine.name }); if (wonWine == undefined) { - const newWonWine = new Wine({ + let newWonWine = new Wine({ name: currentWinner.wine.name, vivinoLink: currentWinner.wine.vivinoLink, rating: currentWinner.wine.rating, diff --git a/schemas/PreLotteryWine.js b/schemas/PreLotteryWine.js new file mode 100644 index 0000000..71699fc --- /dev/null +++ b/schemas/PreLotteryWine.js @@ -0,0 +1,10 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const PreLotteryWine = new Schema({ + name: String, + vivinoLink: String, + rating: Number +}); + +module.exports = mongoose.model("PreLotteryWine", PreLotteryWine); diff --git a/src/components/RegisterPage.vue b/src/components/RegisterPage.vue index 04a45f0..21bdab9 100644 --- a/src/components/RegisterPage.vue +++ b/src/components/RegisterPage.vue @@ -62,6 +62,30 @@