Renamed winner.js to history.js.

This commit is contained in:
2021-01-26 22:14:07 +01:00
parent 1c1f52308f
commit afab4387cc
2 changed files with 23 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
const path = require("path");
const winnerRepository = require(path.join(__dirname, "../winner"));
const historyRepository = require(path.join(__dirname, "../history"));
const sortOptions = ["desc", "asc"];
const includeWinesOptions = ["true", "false"];
@@ -21,7 +21,7 @@ const all = (req, res) => {
});
}
return winnerRepository
return historyRepository
.all(includeWines == "true")
.then(winners =>
res.send({
@@ -54,7 +54,7 @@ const byDate = (req, res) => {
});
}
return winnerRepository
return historyRepository
.byDate(date)
.then(winners =>
res.send({
@@ -90,7 +90,7 @@ const groupByDate = (req, res) => {
});
}
return winnerRepository
return historyRepository
.groupedByDate(includeWines == "true", sort)
.then(lotteries =>
res.send({
@@ -109,7 +109,7 @@ const groupByDate = (req, res) => {
};
const latest = (req, res) => {
return winnerRepository
return historyRepository
.latest()
.then(winners =>
res.send({
@@ -138,7 +138,7 @@ const byName = (req, res) => {
});
}
return winnerRepository
return historyRepository
.byName(name, sort)
.then(winner =>
res.send({
@@ -166,7 +166,7 @@ const groupByColor = (req, res) => {
});
}
return winnerRepository
return historyRepository
.groupByColor(includeWines == "true")
.then(colors =>
res.send({
@@ -194,7 +194,7 @@ const orderByWins = (req, res) => {
});
}
return winnerRepository
return historyRepository
.orderByWins(includeWines == "true")
.then(winners =>
res.send({

View File

@@ -56,6 +56,7 @@ const all = (includeWines = false) => {
}
};
// lottery
const byDate = date => {
const startQueryDate = new Date(date.setHours(0, 0, 0, 0));
const endQueryDate = new Date(date.setHours(24, 59, 59, 99));
@@ -104,6 +105,7 @@ const byDate = date => {
});
};
// highscore
const byName = (name, sort = "desc") => {
return Winner.findOne({ name }, ["name", "wins"])
.sort("-wins.date")
@@ -118,6 +120,7 @@ const byName = (name, sort = "desc") => {
});
};
// lottery
const latest = () => {
const query = [
{
@@ -163,6 +166,7 @@ const latest = () => {
return Winner.aggregate(query).then(winners => winners[0]);
};
// lottery - byDate
const groupByDate = (includeWines = false, sort = "desc") => {
const query = [
{
@@ -208,6 +212,7 @@ const groupByDate = (includeWines = false, sort = "desc") => {
return Winner.aggregate(query).then(lotteries => (sort != "asc" ? lotteries : lotteries.reverse()));
};
// highscore - byColor
const groupByColor = (includeWines = false) => {
const query = [
{
@@ -255,6 +260,9 @@ const groupByColor = (includeWines = false) => {
return Winner.aggregate(query);
};
// highscore - byWineOccurences
// highscore - byWinCount
const orderByWins = (includeWines = false) => {
let query = [
{
@@ -304,6 +312,13 @@ const orderByWins = (includeWines = false) => {
return Winner.aggregate(query);
};
// highscore - deleteWinner : remove for GDPR purpose
// lottery - deleteWinner : remove for GDPR purpose
// lottery - update : manual lottery
// lottery - add : manual lottery
// lottery - archive
module.exports = {
addWinnerWithWine,
all,