Renamed winner.js to history.js.
This commit is contained in:
		| @@ -1,5 +1,5 @@ | |||||||
| const path = require("path"); | const path = require("path"); | ||||||
| const winnerRepository = require(path.join(__dirname, "../winner")); | const historyRepository = require(path.join(__dirname, "../history")); | ||||||
| 
 | 
 | ||||||
| const sortOptions = ["desc", "asc"]; | const sortOptions = ["desc", "asc"]; | ||||||
| const includeWinesOptions = ["true", "false"]; | const includeWinesOptions = ["true", "false"]; | ||||||
| @@ -21,7 +21,7 @@ const all = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .all(includeWines == "true") |     .all(includeWines == "true") | ||||||
|     .then(winners => |     .then(winners => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -54,7 +54,7 @@ const byDate = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .byDate(date) |     .byDate(date) | ||||||
|     .then(winners => |     .then(winners => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -90,7 +90,7 @@ const groupByDate = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .groupedByDate(includeWines == "true", sort) |     .groupedByDate(includeWines == "true", sort) | ||||||
|     .then(lotteries => |     .then(lotteries => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -109,7 +109,7 @@ const groupByDate = (req, res) => { | |||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const latest = (req, res) => { | const latest = (req, res) => { | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .latest() |     .latest() | ||||||
|     .then(winners => |     .then(winners => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -138,7 +138,7 @@ const byName = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .byName(name, sort) |     .byName(name, sort) | ||||||
|     .then(winner => |     .then(winner => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -166,7 +166,7 @@ const groupByColor = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .groupByColor(includeWines == "true") |     .groupByColor(includeWines == "true") | ||||||
|     .then(colors => |     .then(colors => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -194,7 +194,7 @@ const orderByWins = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   return winnerRepository |   return historyRepository | ||||||
|     .orderByWins(includeWines == "true") |     .orderByWins(includeWines == "true") | ||||||
|     .then(winners => |     .then(winners => | ||||||
|       res.send({ |       res.send({ | ||||||
| @@ -56,6 +56,7 @@ const all = (includeWines = false) => { | |||||||
|   } |   } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // lottery
 | ||||||
| const byDate = date => { | const byDate = date => { | ||||||
|   const startQueryDate = new Date(date.setHours(0, 0, 0, 0)); |   const startQueryDate = new Date(date.setHours(0, 0, 0, 0)); | ||||||
|   const endQueryDate = new Date(date.setHours(24, 59, 59, 99)); |   const endQueryDate = new Date(date.setHours(24, 59, 59, 99)); | ||||||
| @@ -104,6 +105,7 @@ const byDate = date => { | |||||||
|   }); |   }); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // highscore
 | ||||||
| const byName = (name, sort = "desc") => { | const byName = (name, sort = "desc") => { | ||||||
|   return Winner.findOne({ name }, ["name", "wins"]) |   return Winner.findOne({ name }, ["name", "wins"]) | ||||||
|     .sort("-wins.date") |     .sort("-wins.date") | ||||||
| @@ -118,6 +120,7 @@ const byName = (name, sort = "desc") => { | |||||||
|     }); |     }); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // lottery
 | ||||||
| const latest = () => { | const latest = () => { | ||||||
|   const query = [ |   const query = [ | ||||||
|     { |     { | ||||||
| @@ -163,6 +166,7 @@ const latest = () => { | |||||||
|   return Winner.aggregate(query).then(winners => winners[0]); |   return Winner.aggregate(query).then(winners => winners[0]); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // lottery - byDate
 | ||||||
| const groupByDate = (includeWines = false, sort = "desc") => { | const groupByDate = (includeWines = false, sort = "desc") => { | ||||||
|   const query = [ |   const query = [ | ||||||
|     { |     { | ||||||
| @@ -208,6 +212,7 @@ const groupByDate = (includeWines = false, sort = "desc") => { | |||||||
|   return Winner.aggregate(query).then(lotteries => (sort != "asc" ? lotteries : lotteries.reverse())); |   return Winner.aggregate(query).then(lotteries => (sort != "asc" ? lotteries : lotteries.reverse())); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // highscore - byColor
 | ||||||
| const groupByColor = (includeWines = false) => { | const groupByColor = (includeWines = false) => { | ||||||
|   const query = [ |   const query = [ | ||||||
|     { |     { | ||||||
| @@ -255,6 +260,9 @@ const groupByColor = (includeWines = false) => { | |||||||
|   return Winner.aggregate(query); |   return Winner.aggregate(query); | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | // highscore - byWineOccurences
 | ||||||
|  | 
 | ||||||
|  | // highscore - byWinCount
 | ||||||
| const orderByWins = (includeWines = false) => { | const orderByWins = (includeWines = false) => { | ||||||
|   let query = [ |   let query = [ | ||||||
|     { |     { | ||||||
| @@ -304,6 +312,13 @@ const orderByWins = (includeWines = false) => { | |||||||
|   return Winner.aggregate(query); |   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 = { | module.exports = { | ||||||
|   addWinnerWithWine, |   addWinnerWithWine, | ||||||
|   all, |   all, | ||||||
		Reference in New Issue
	
	Block a user