Add sms capabilities, and online-fixing of everything #15

Merged
kasperrt merged 5 commits from feat/sms-ing into master 2020-04-06 07:39:22 +00:00
2 changed files with 62 additions and 0 deletions
Showing only changes of commit 39c4d8f134 - Show all commits

35
api/person.js Normal file
View File

@@ -0,0 +1,35 @@
const path = require("path");
const Highscore = require(path.join(__dirname + "/../schemas/Highscore"));
async function findSavePerson(foundWinner, wonWine) {
let person = await Highscore.findOne({
name: foundWinner.name
});
if (person == undefined) {
let newPerson = new Highscore({
name: foundWinner.name,
wins: [
{
color: foundWinner.color,
date: date,
wine: wonWine
}
]
});
await newPerson.save();
} else {
person.wins.push({
color: foundWinner.color,
date: date,
wine: wonWine
});
person.markModified("wins");
await person.save();
}
return person;
}
module.exports.findSavePerson = findSavePerson;

27
api/wine.js Normal file
View File

@@ -0,0 +1,27 @@
const path = require("path");
const Wine = require(path.join(__dirname + "/../schemas/Wine"));
async function findSaveWine(prelotteryWine) {
let wonWine = await Wine.findOne({ name: prelotteryWine.name });
if (wonWine == undefined) {
let newWonWine = new Wine({
name: prelotteryWine.name,
vivinoLink: prelotteryWine.vivinoLink,
rating: prelotteryWine.rating,
occurences: 1,
image: prelotteryWine.image,
id: prelotteryWine.id
});
await newWonWine.save();
wonWine = newWonWine;
} else {
wonWine.occurences += 1;
wonWine.image = prelotteryWine.image;
wonWine.id = prelotteryWine.id;
await wonWine.save();
}
return wonWine;
}
module.exports.findSaveWine = findSaveWine;