Repository gets new search winner by query func.
Has sort parameter that defaults to newest first.
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user