Pulled feature branch up-to-date w/ master.

This commit is contained in:
2020-11-20 19:15:46 +01:00
32 changed files with 1511 additions and 1985 deletions

View File

@@ -69,7 +69,7 @@ const all = (req, res) => {
const latest = (req, res) => {
return groupHighscoreByDate()
.then(lotteries => lotteries.shift())
.then(lotteries => lotteries.shift()) // first element in list
.then(latestLottery => resolveWineReferences(latestLottery, "winners"))
.then(lottery => res.send({
message: "Latest lottery!",
@@ -120,7 +120,7 @@ const byName = (req, res) => {
.then(highscore => res.send({
message: `Lottery winnings for name: ${ name }.`,
name: highscore.name,
highscore: highscore.wins
highscore: sortNewestFirst(highscore.wins)
}))
}

View File

@@ -20,20 +20,20 @@ const deleteRequestedWineById = async (req, res) => {
return res.json({
message: `Slettet vin med id: ${id}`,
success: true
});
});
}
const getAllRequestedWines = async (req, res) => {
const allWines = await RequestedWine.find({}).populate("wine");
return res.json(allWines);
}
const requestNewWine = async (req, res) => {
const {wine} = req.body
let thisWineIsLOKO = await Wine.findOne({id: wine.id})
if(thisWineIsLOKO == undefined){
thisWineIsLOKO = new Wine({
name: wine.name,
@@ -45,9 +45,9 @@ const requestNewWine = async (req, res) => {
});
await thisWineIsLOKO.save()
}
let requestedWine = await RequestedWine.findOne({ "wineId": wine.id})
if(requestedWine == undefined){
requestedWine = new RequestedWine({
count: 1,
@@ -58,7 +58,7 @@ const requestNewWine = async (req, res) => {
requestedWine.count += 1;
}
await requestedWine.save()
return res.send(requestedWine);
}