Repository gets new search winner by query func.

Has sort parameter that defaults to newest first.
This commit is contained in:
2021-02-17 19:24:38 +01:00
parent bca4558d59
commit 1c40fae69d

View File

@@ -125,6 +125,18 @@ const byName = (name, sort = "desc") => {
}); });
}; };
// highscore
const search = (query, sort = "desc") => {
return Winner.find({ name: { $regex: query, $options: "i" } }, ["name"]).then(winners => {
if (winners) {
winners = sort === "desc" ? winners.reverse() : winners;
return winners;
} else {
throw new HistoryForUserNotFound();
}
});
};
// lottery // lottery
const latest = () => { const latest = () => {
const query = [ const query = [
@@ -328,6 +340,8 @@ module.exports = {
addWinnerWithWine, addWinnerWithWine,
all, all,
byDate, byDate,
byName,
search,
latest, latest,
groupByDate, groupByDate,
groupByColor, groupByColor,