From 795f110e1b8f8da212713192dfa0b4a56a5eb100 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 11 Oct 2020 22:18:37 +0200 Subject: [PATCH 1/4] Syntax error w/ capitalization crashes draw! --- api/virtualRegistration.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/virtualRegistration.js b/api/virtualRegistration.js index 74fb652..533dd1d 100644 --- a/api/virtualRegistration.js +++ b/api/virtualRegistration.js @@ -95,15 +95,19 @@ const registerWinnerSelection = async (req, res) => { })) }; -const chooseLastWineForUser = (winner, prelotteryWine) => { +const chooseLastWineForUser = (winner, preLotteryWine) => { let date = new Date(); date.setHours(5, 0, 0, 0); return _wineFunctions.findSaveWine(preLotteryWine) .then(wonWine => _personFunctions.findSavePerson(winner, wonWine, date)) - .then(() => prelotteryWine.delete()) + .then(() => preLotteryWine.delete()) .then(() => Message.sendLastWinnerMessage(winner, preLotteryWine)) - .then(() => winner.delete()); + .then(() => winner.delete()) + .catch(err => { + console.log("Error thrown from chooseLastWineForUser: " + err); + throw err; + }) } const findAndNotifyNextWinner = async () => { From 439191008a5e2180fc1061ee776ec2a2e86a2609 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 11 Oct 2020 22:18:59 +0200 Subject: [PATCH 2/4] More logging to console during draw. --- api/virtualRegistration.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/api/virtualRegistration.js b/api/virtualRegistration.js index 533dd1d..8cf204e 100644 --- a/api/virtualRegistration.js +++ b/api/virtualRegistration.js @@ -117,10 +117,13 @@ const findAndNotifyNextWinner = async () => { let winesLeft = await PreLotteryWine.find(); if (winnersLeft.length > 1) { + console.log("multiple winners left, choose next in line") nextWinner = winnersLeft[0]; // multiple winners left, choose next in line } else if (winnersLeft.length == 1 && winesLeft.length > 1) { + console.log("one winner left, but multiple wines") nextWinner = winnersLeft[0] // one winner left, but multiple wines } else if (winnersLeft.length == 1 && winesLeft.length == 1) { + console.log("one winner and one wine left, choose for user") nextWinner = winnersLeft[0] // one winner and one wine left, choose for user wine = winesLeft[0] return chooseLastWineForUser(nextWinner, wine); From b3b5e87ab5e032b34ffd256d6ffb253cf4e93bcd Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 11 Oct 2020 22:19:25 +0200 Subject: [PATCH 3/4] Log gateway response data. --- api/message.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/message.js b/api/message.js index a763a7b..82393ff 100644 --- a/api/message.js +++ b/api/message.js @@ -82,7 +82,11 @@ async function gatewayRequest(body) { res.setEncoding('utf8'); if (res.statusCode == 200) { - res.on("data", (d) => resolve(JSON.parse(d))); + res.on("data", (data) => { + console.log("Response from message gateway:", data) + + resolve(JSON.parse(data)) + }); } else { res.on("data", (data) => { data = JSON.parse(data); From e76e814877981cb904d31dba6642e626836cdc03 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Sun, 11 Oct 2020 22:20:09 +0200 Subject: [PATCH 4/4] Always return success bool from getWinner endpoint --- api/virtualLottery.js | 5 ++++- src/components/VirtualLotteryRegistrationPage.vue | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/api/virtualLottery.js b/api/virtualLottery.js index e9ec85f..74224d6 100644 --- a/api/virtualLottery.js +++ b/api/virtualLottery.js @@ -187,7 +187,10 @@ const drawWinner = async (req, res) => { ); await newWinnerElement.save(); - return res.json(winner); + return res.json({ + success: true, + winner + }); }; const finish = async (req, res) => { diff --git a/src/components/VirtualLotteryRegistrationPage.vue b/src/components/VirtualLotteryRegistrationPage.vue index 153c6e9..24145a1 100644 --- a/src/components/VirtualLotteryRegistrationPage.vue +++ b/src/components/VirtualLotteryRegistrationPage.vue @@ -229,7 +229,8 @@ export default { this.drawingWinner = true; let response = await getVirtualWinner(); - if (response) { + if (response.success) { + console.log("Winner:", response.winner); if (this.currentWinners < this.numberOfWinners) { this.countdown(); } else { @@ -245,7 +246,7 @@ export default { this.getAttendees(); } else { this.drawingWinner = false; - alert("Noe gikk galt under trekningen..!"); + alert("Noe gikk galt under trekningen..! " + response["message"]); } } },