diff --git a/api/retrieve.js b/api/retrieve.js index 95fbdaf..abb4a77 100644 --- a/api/retrieve.js +++ b/api/retrieve.js @@ -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 }); }); diff --git a/api/update.js b/api/update.js index a604a68..30dae8f 100644 --- a/api/update.js +++ b/api/update.js @@ -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(); diff --git a/schemas/Purchase.js b/schemas/Purchase.js index fae2327..63e2baa 100644 --- a/schemas/Purchase.js +++ b/schemas/Purchase.js @@ -7,6 +7,8 @@ const Purchase = new Schema({ red: Number, yellow: Number, green: Number, + bought: Number, + stolen: Number, wines: [ { type: Schema.Types.ObjectId, diff --git a/src/components/RegisterPage.vue b/src/components/RegisterPage.vue index 118004d..f3edff0 100644 --- a/src/components/RegisterPage.vue +++ b/src/components/RegisterPage.vue @@ -18,6 +18,10 @@ +
+ + +
@@ -41,25 +45,13 @@
- +
- +
- +
@@ -81,11 +73,7 @@
- +
@@ -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; diff --git a/src/ui/TotalBought.vue b/src/ui/TotalBought.vue index 398c788..55fcb9c 100644 --- a/src/ui/TotalBought.vue +++ b/src/ui/TotalBought.vue @@ -28,6 +28,7 @@ {{ total }} kjøpte
{{ totalWin }} vinn
+
{{ stolen }} stjålet
@@ -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