more fun functions
This commit is contained in:
@@ -9,11 +9,19 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", {
|
|||||||
const Purchase = require(path.join(__dirname + "/../schemas/Purchase"));
|
const Purchase = require(path.join(__dirname + "/../schemas/Purchase"));
|
||||||
const Wine = require(path.join(__dirname + "/../schemas/Wine"));
|
const Wine = require(path.join(__dirname + "/../schemas/Wine"));
|
||||||
const Highscore = require(path.join(__dirname + "/../schemas/Highscore"));
|
const Highscore = require(path.join(__dirname + "/../schemas/Highscore"));
|
||||||
|
const PreLotteryWine = require(path.join(
|
||||||
|
__dirname + "/../schemas/PreLotteryWine"
|
||||||
|
));
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
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) => {
|
router.route("/purchase/statistics").get(async (req, res) => {
|
||||||
let purchases = await Purchase.find()
|
let purchases = await Purchase.find()
|
||||||
.populate("wines")
|
.populate("wines")
|
||||||
|
|||||||
@@ -8,17 +8,44 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", {
|
|||||||
|
|
||||||
const Purchase = require(path.join(__dirname + "/../schemas/Purchase"));
|
const Purchase = require(path.join(__dirname + "/../schemas/Purchase"));
|
||||||
const Wine = require(path.join(__dirname + "/../schemas/Wine"));
|
const Wine = require(path.join(__dirname + "/../schemas/Wine"));
|
||||||
|
const PreLotteryWine = require(path.join(
|
||||||
|
__dirname + "/../schemas/PreLotteryWine"
|
||||||
|
));
|
||||||
const Highscore = require(path.join(__dirname + "/../schemas/Highscore"));
|
const Highscore = require(path.join(__dirname + "/../schemas/Highscore"));
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
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) => {
|
router.route("/log").post(async (req, res) => {
|
||||||
if (!req.isAuthenticated()) {
|
if (!req.isAuthenticated()) {
|
||||||
res.send(false);
|
res.send(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await PreLotteryWine.deleteMany();
|
||||||
|
|
||||||
const purchaseBody = req.body.purchase;
|
const purchaseBody = req.body.purchase;
|
||||||
const winnersBody = req.body.winners;
|
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 });
|
let wonWine = await Wine.findOne({ name: currentWinner.wine.name });
|
||||||
if (wonWine == undefined) {
|
if (wonWine == undefined) {
|
||||||
const newWonWine = new Wine({
|
let newWonWine = new Wine({
|
||||||
name: currentWinner.wine.name,
|
name: currentWinner.wine.name,
|
||||||
vivinoLink: currentWinner.wine.vivinoLink,
|
vivinoLink: currentWinner.wine.vivinoLink,
|
||||||
rating: currentWinner.wine.rating,
|
rating: currentWinner.wine.rating,
|
||||||
|
|||||||
10
schemas/PreLotteryWine.js
Normal file
10
schemas/PreLotteryWine.js
Normal file
@@ -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);
|
||||||
@@ -62,6 +62,30 @@
|
|||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="button-container">
|
||||||
|
<button @click="addWine">Legg til en vin</button>
|
||||||
|
<button @click="sendWines">Send inn viner</button>
|
||||||
|
</div>
|
||||||
|
<div class="wines-container" v-if="wines.length > 0">
|
||||||
|
Viner
|
||||||
|
<div v-for="wine in wines" class="wine-element">
|
||||||
|
<hr />
|
||||||
|
<div class="label-div">
|
||||||
|
<input type="text" v-model="wine.name" placeholder="Vin-navn" />
|
||||||
|
</div>
|
||||||
|
<div class="label-div">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
v-model="wine.vivinoLink"
|
||||||
|
placeholder="Vivino-link"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="label-div">
|
||||||
|
<input type="text" v-model="wine.rating" placeholder="Rating" />
|
||||||
|
</div>
|
||||||
|
<hr />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -73,10 +97,51 @@ export default {
|
|||||||
blue: 0,
|
blue: 0,
|
||||||
green: 0,
|
green: 0,
|
||||||
yellow: 0,
|
yellow: 0,
|
||||||
winners: []
|
winners: [],
|
||||||
|
wines: []
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
async mounted() {
|
||||||
|
const _wines = await fetch("/api/wines/prelottery");
|
||||||
|
const wines = await _wines.json();
|
||||||
|
for (let i = 0; i < wines.length; i++) {
|
||||||
|
let wine = wines[i];
|
||||||
|
this.winners.push({
|
||||||
|
name: "",
|
||||||
|
color: "",
|
||||||
|
wine: {
|
||||||
|
name: wine.name,
|
||||||
|
vivinoLink: wine.vivinoLink,
|
||||||
|
rating: wine.rating
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
addWine: function(event) {
|
||||||
|
this.wines.push({
|
||||||
|
name: "",
|
||||||
|
vivinoLink: "",
|
||||||
|
rating: ""
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sendWines: async function() {
|
||||||
|
let _response = await fetch("/api/log/wines", {
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
// 'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(this.wines)
|
||||||
|
});
|
||||||
|
let response = await _response.json();
|
||||||
|
if (response == true) {
|
||||||
|
alert("Sendt!");
|
||||||
|
window.location.reload();
|
||||||
|
} else {
|
||||||
|
alert("Noe gikk galt under innsending");
|
||||||
|
}
|
||||||
|
},
|
||||||
addWinner: function(event) {
|
addWinner: function(event) {
|
||||||
this.winners.push({
|
this.winners.push({
|
||||||
name: "",
|
name: "",
|
||||||
@@ -180,7 +245,8 @@ hr {
|
|||||||
width: 50vw;
|
width: 50vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
.winner-container {
|
.winner-container,
|
||||||
|
.wine-container {
|
||||||
width: 50vw;
|
width: 50vw;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
@@ -190,6 +256,7 @@ hr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.winner-element,
|
.winner-element,
|
||||||
|
.wine-element,
|
||||||
.color-container,
|
.color-container,
|
||||||
.button-container {
|
.button-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
Reference in New Issue
Block a user