diff --git a/api/message.js b/api/message.js index 1053091..e8a1eec 100644 --- a/api/message.js +++ b/api/message.js @@ -41,6 +41,7 @@ async function sendMessageTooLate(winnerObject) { } async function sendMessageToUser(phoneNumber, message) { + try { request.post( { url: `https://gatewayapi.com/rest/mtsms?token=${config.gatewayToken}`, @@ -53,8 +54,14 @@ async function sendMessageToUser(phoneNumber, message) { }, function(err, r, body) { console.log(err ? err : body); + if(err) { + console.log(phoneNumber, message); + } } ); + } catch(e) { + console.log(phoneNumber, message); + } } async function sendUpdate(winners) { diff --git a/api/person.js b/api/person.js index bfce82d..8a10879 100644 --- a/api/person.js +++ b/api/person.js @@ -1,7 +1,7 @@ const path = require("path"); const Highscore = require(path.join(__dirname + "/../schemas/Highscore")); -async function findSavePerson(foundWinner, wonWine) { +async function findSavePerson(foundWinner, wonWine, date) { let person = await Highscore.findOne({ name: foundWinner.name }); diff --git a/api/update.js b/api/update.js index 2aad063..5fd2c12 100644 --- a/api/update.js +++ b/api/update.js @@ -86,7 +86,7 @@ router.route("/log").post(mustBeAuthenticated, async (req, res) => { let wonWine = await _wineFunctions.findSaveWine(currentWinner); winesThisDate.push(wonWine); - await _personFunctions.findSavePerson(currentWinner, wonWine); + await _personFunctions.findSavePerson(currentWinner, wonWine, date); } let purchase = new Purchase({ diff --git a/api/virtualRegistration.js b/api/virtualRegistration.js index c6c033c..b3c128e 100644 --- a/api/virtualRegistration.js +++ b/api/virtualRegistration.js @@ -88,7 +88,7 @@ router.route("/:id").post(async (req, res) => { let wonWine = await _wineFunctions.findSaveWine(prelotteryWine); await prelotteryWine.delete(); - await _personFunctions.findSavePerson(foundWinner, wonWine); + await _personFunctions.findSavePerson(foundWinner, wonWine, date); await foundWinner.delete(); @@ -111,10 +111,11 @@ async function chooseForUser(winner, prelotteryWine) { let date = new Date(); date.setHours(5, 0, 0, 0); let wonWine = await _wineFunctions.findSaveWine(prelotteryWine); - await _personFunctions.findSavePerson(winner, wonWine); + await _personFunctions.findSavePerson(winner, wonWine, date); await prelotteryWine.delete(); - Message.sendWonWineMessage(winner, prelotteryWine); + await Message.sendWonWineMessage(winner, prelotteryWine); + await winner.delete(); } function startTimeout(id) { diff --git a/config/defaults/lottery.js b/config/defaults/lottery.js index f341975..d0b6540 100644 --- a/config/defaults/lottery.js +++ b/config/defaults/lottery.js @@ -11,7 +11,7 @@ try { message: "INSERT MESSAGE", date: 5, hours: 15, - apiUrl: "https://lottis.vin", + apiUrl: "http://localhost:30030", gatewayToken: undefined }; }