Added stolen functionality
This commit is contained in:
@@ -35,12 +35,16 @@ router.route("/purchase/statistics/color").get(async (req, res) => {
|
||||
let blue = 0;
|
||||
let yellow = 0;
|
||||
let green = 0;
|
||||
let stolen = 0;
|
||||
for (let i = 0; i < countColor.length; i++) {
|
||||
let element = countColor[i];
|
||||
red += element.red;
|
||||
blue += element.blue;
|
||||
yellow += element.yellow;
|
||||
green += element.green;
|
||||
if (element.stolen != undefined) {
|
||||
stolen += element.stolen;
|
||||
}
|
||||
}
|
||||
|
||||
const highscore = await Highscore.find();
|
||||
@@ -88,6 +92,7 @@ router.route("/purchase/statistics/color").get(async (req, res) => {
|
||||
total: yellow,
|
||||
win: yellowWin
|
||||
},
|
||||
stolen: stolen,
|
||||
total: total
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,6 +55,9 @@ router.route("/log").post(async (req, res) => {
|
||||
const yellow = purchaseBody.yellow;
|
||||
const green = purchaseBody.green;
|
||||
|
||||
const bought = purchaseBody.bought;
|
||||
const stolen = purchaseBody.stolen;
|
||||
|
||||
const winesThisDate = [];
|
||||
|
||||
for (let i = 0; i < winnersBody.length; i++) {
|
||||
@@ -111,7 +114,9 @@ router.route("/log").post(async (req, res) => {
|
||||
yellow: yellow,
|
||||
red: red,
|
||||
green: green,
|
||||
wines: winesThisDate
|
||||
wines: winesThisDate,
|
||||
bought: bought,
|
||||
stolen: stolen
|
||||
});
|
||||
|
||||
await purchase.save();
|
||||
|
||||
@@ -7,6 +7,8 @@ const Purchase = new Schema({
|
||||
red: Number,
|
||||
yellow: Number,
|
||||
green: Number,
|
||||
bought: Number,
|
||||
stolen: Number,
|
||||
wines: [
|
||||
{
|
||||
type: Schema.Types.ObjectId,
|
||||
|
||||
@@ -18,6 +18,10 @@
|
||||
<label for="yellow">Gul</label>
|
||||
<input id="yellow" type="number" v-model="yellow" />
|
||||
</div>
|
||||
<div class="label-div">
|
||||
<label for="yellow">Kjøpt for sum</label>
|
||||
<input id="yellow" type="number" v-model="payed" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="button-container">
|
||||
<button @click="addWinner">Legg til en vinner</button>
|
||||
@@ -41,25 +45,13 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="label-div">
|
||||
<input
|
||||
type="text"
|
||||
v-model="winner.wine.name"
|
||||
placeholder="Vin-navn"
|
||||
/>
|
||||
<input type="text" v-model="winner.wine.name" placeholder="Vin-navn" />
|
||||
</div>
|
||||
<div class="label-div">
|
||||
<input
|
||||
type="text"
|
||||
v-model="winner.wine.vivinoLink"
|
||||
placeholder="Vivino-link"
|
||||
/>
|
||||
<input type="text" v-model="winner.wine.vivinoLink" placeholder="Vivino-link" />
|
||||
</div>
|
||||
<div class="label-div">
|
||||
<input
|
||||
type="text"
|
||||
v-model="winner.wine.rating"
|
||||
placeholder="Rating"
|
||||
/>
|
||||
<input type="text" v-model="winner.wine.rating" placeholder="Rating" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="wine-image">
|
||||
@@ -81,11 +73,7 @@
|
||||
<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"
|
||||
/>
|
||||
<input type="text" v-model="wine.vivinoLink" placeholder="Vivino-link" />
|
||||
</div>
|
||||
<div class="label-div">
|
||||
<input type="text" v-model="wine.id" placeholder="Id" />
|
||||
@@ -110,6 +98,7 @@ export default {
|
||||
blue: 0,
|
||||
green: 0,
|
||||
yellow: 0,
|
||||
payed: 0,
|
||||
winners: [],
|
||||
wines: []
|
||||
};
|
||||
@@ -199,6 +188,19 @@ export default {
|
||||
return;
|
||||
}
|
||||
|
||||
sendObject.purchase.bought =
|
||||
parseInt(this.blue) +
|
||||
parseInt(this.red) +
|
||||
parseInt(this.green) +
|
||||
parseInt(this.yellow);
|
||||
const stolen = sendObject.purchase.bought - parseInt(this.payed) / 10;
|
||||
console.log(sendObject.purchase.bought, this.payed);
|
||||
if (isNaN(stolen) || stolen == undefined) {
|
||||
alert("Betalt må registreres");
|
||||
return;
|
||||
}
|
||||
sendObject.purchase.stolen = stolen;
|
||||
|
||||
if (sendObject.winners.length == 0) {
|
||||
alert("Det må være med vinnere");
|
||||
return;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<span class="total">{{ total }}</span> kjøpte
|
||||
</div>
|
||||
<div>{{ totalWin }} vinn</div>
|
||||
<div>{{ stolen }} stjålet</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -44,6 +45,7 @@ export default {
|
||||
green: 0,
|
||||
total: 0,
|
||||
totalWin: 0,
|
||||
stolen: 0,
|
||||
wins: 0,
|
||||
redPercentage: 0,
|
||||
yellowPercentage: 0,
|
||||
@@ -61,6 +63,7 @@ export default {
|
||||
this.total = response.total;
|
||||
this.totalWin =
|
||||
this.red.win + this.yellow.win + this.blue.win + this.green.win;
|
||||
this.stolen = response.stolen;
|
||||
|
||||
this.redPercentage = this.round(
|
||||
this.red.win == 0 ? 0 : (this.red.win / this.totalWin) * 100
|
||||
|
||||
Reference in New Issue
Block a user