diff --git a/api/lottery.js b/api/lottery.js index 17d8e29..e336ada 100644 --- a/api/lottery.js +++ b/api/lottery.js @@ -1,10 +1,5 @@ const path = require('path'); -const mongoose = require('mongoose'); -mongoose.connect('mongodb://localhost:27017/vinlottis', { - useNewUrlParser: true -}) - const Highscore = require(path.join(__dirname + '/../schemas/Highscore')); const Wine = require(path.join(__dirname + '/../schemas/Wine')); @@ -82,11 +77,13 @@ const byEpochDate = (req, res) => { .then(highscore => getHighscoreByDates(highscore)) .then(async (lotteries) => { const lottery = lotteries[date]; + let highscoreWithResolvedWines = await resolveWineReferences(lottery) + highscoreWithResolvedWines = highscoreWithResolvedWines.reverse() if (lottery != null) { return res.send({ message: `Lottery for date: ${dateString}`, - lottery: await resolveWineReferences(lottery) + lottery: highscoreWithResolvedWines }) } else { return res.status(404).send({ @@ -98,15 +95,18 @@ const byEpochDate = (req, res) => { const byName = (req, res) => { const { name } = req.params; + const regexName = new RegExp(name, "i"); // lowercase regex of the name - return Highscore.find({ name }) + return Highscore.find({ "name": { $regex : regexName } }) .then(async (highscore) => { highscore = highscore[0] if (highscore) { - const highscoreWithResolvedWines = await resolveWineReferences(highscore.wins) + let highscoreWithResolvedWines = await resolveWineReferences(highscore.wins) + highscoreWithResolvedWines = highscoreWithResolvedWines.reverse() return res.send({ message: `Lottery winnings by name: ${name}`, + name: name, highscore: highscoreWithResolvedWines }) } else { diff --git a/api/retrieve.js b/api/retrieve.js index 92bb2a6..d377c60 100644 --- a/api/retrieve.js +++ b/api/retrieve.js @@ -1,8 +1,4 @@ const path = require("path"); -const mongoose = require("mongoose"); -mongoose.connect("mongodb://localhost:27017/vinlottis", { - useNewUrlParser: true -}); const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); const Wine = require(path.join(__dirname + "/../schemas/Wine")); diff --git a/api/subscriptions.js b/api/subscriptions.js index 574280c..1d61a08 100644 --- a/api/subscriptions.js +++ b/api/subscriptions.js @@ -2,13 +2,8 @@ const express = require("express"); const path = require("path"); const router = express.Router(); const webpush = require("web-push"); //requiring the web-push module -const mongoose = require("mongoose"); const schedule = require("node-schedule"); -mongoose.connect("mongodb://localhost:27017/vinlottis", { - useNewUrlParser: true -}); - const mustBeAuthenticated = require(path.join( __dirname + "/../middleware/mustBeAuthenticated" )); diff --git a/api/update.js b/api/update.js index 785ae0c..9761c40 100644 --- a/api/update.js +++ b/api/update.js @@ -1,9 +1,5 @@ const express = require("express"); const path = require("path"); -const mongoose = require("mongoose"); -mongoose.connect("mongodb://localhost:27017/vinlottis", { - useNewUrlParser: true -}); const sub = require(path.join(__dirname + "/../api/subscriptions")); diff --git a/src/api.js b/src/api.js index 05145b9..2733701 100644 --- a/src/api.js +++ b/src/api.js @@ -333,6 +333,19 @@ const historyAll = () => { }); } +const getWinnerByName = (name) => { + const encodedName = encodeURIComponent(name) + const url = new URL(`/api/lottery/by-name/${name}`, BASE_URL); + + return fetch(url.href).then(resp => { + if (resp.ok) { + return resp.json(); + } else { + return handleErrors(resp); + } + }) +} + export { statistics, colorStatistics, @@ -364,5 +377,6 @@ export { finishedDraw, getAmIWinner, postWineChosen, - historyAll + historyAll, + getWinnerByName }; diff --git a/src/components/HighscorePage.vue b/src/components/HighscorePage.vue index 574f45c..3b9bf8d 100644 --- a/src/components/HighscorePage.vue +++ b/src/components/HighscorePage.vue @@ -1,56 +1,24 @@ @@ -58,16 +26,15 @@ diff --git a/src/components/PersonalHighscorePage.vue b/src/components/PersonalHighscorePage.vue new file mode 100644 index 0000000..69610cd --- /dev/null +++ b/src/components/PersonalHighscorePage.vue @@ -0,0 +1,273 @@ + + + + + \ No newline at end of file diff --git a/src/components/TodaysPage.vue b/src/components/TodaysPage.vue index 0dfdf12..de81fc1 100644 --- a/src/components/TodaysPage.vue +++ b/src/components/TodaysPage.vue @@ -11,6 +11,7 @@ diff --git a/src/components/VirtualLotteryRegistrationPage.vue b/src/components/VirtualLotteryRegistrationPage.vue index cff8fe8..153c6e9 100644 --- a/src/components/VirtualLotteryRegistrationPage.vue +++ b/src/components/VirtualLotteryRegistrationPage.vue @@ -18,7 +18,7 @@

Vinnere

-
+
{{ winner.name }} {{ winner.phoneNumber }} Rød: {{ winner.red }} @@ -47,11 +47,11 @@ {{ attendee.name }} {{ attendee.phoneNumber }}
-
-
{{ attendee.red }}
-
{{ attendee.blue }}
-
{{ attendee.green }}
-
{{ attendee.yellow }}
+
+
{{ attendee.red }}
+
{{ attendee.blue }}
+
{{ attendee.green }}
+
{{ attendee.yellow }}
@@ -140,7 +140,7 @@ export default { blue: 0, green: 0, yellow: 0, - ballots: 0, + raffles: 0, randomColors: false, attendees: [], winners: [], @@ -197,7 +197,7 @@ export default { blue: this.blue, green: this.green, yellow: this.yellow, - ballots: this.ballots + raffles: this.raffles }); if (response == true) { @@ -354,7 +354,7 @@ hr { } } -.ballot-element { +.raffle-element { width: 140px; height: 150px; margin: 20px 0; @@ -378,19 +378,19 @@ hr { font-size: 1rem; } - &.green-ballot { + &.green-raffle { background-color: $light-green; } - &.blue-ballot { + &.blue-raffle { background-color: $light-blue; } - &.yellow-ballot { + &.yellow-raffle { background-color: $light-yellow; } - &.red-ballot { + &.red-raffle { background-color: $light-red; } } @@ -422,7 +422,7 @@ button { margin: 0 auto; & .name-and-phone, - & .ballots-container { + & .raffles-container { display: flex; justify-content: center; } @@ -431,7 +431,7 @@ button { flex-direction: column; } - & .ballots-container { + & .raffles-container { flex-direction: row; } } diff --git a/src/components/WinnerPage.vue b/src/components/WinnerPage.vue index 434f9d7..c60472c 100644 --- a/src/components/WinnerPage.vue +++ b/src/components/WinnerPage.vue @@ -29,7 +29,7 @@