Get all wines with limit parameter.
This commit is contained in:
		| @@ -222,6 +222,15 @@ const orderByWins = (req, res) => { | |||||||
|     }); |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   if (limit && isNaN(limit)) { | ||||||
|  |     return res.status(400).send({ | ||||||
|  |       message: "If limit query parameter is provided it must be a number", | ||||||
|  |       success: false | ||||||
|  |     }); | ||||||
|  |   } else if (!!!isNaN(limit)) { | ||||||
|  |     limit = Number(limit); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   return historyRepository |   return historyRepository | ||||||
|     .orderByWins(includeWines == "true", limit) |     .orderByWins(includeWines == "true", limit) | ||||||
|     .then(winners => |     .then(winners => | ||||||
|   | |||||||
| @@ -3,9 +3,19 @@ const wineRepository = require(path.join(__dirname, "../wine")); | |||||||
|  |  | ||||||
| const allWines = (req, res) => { | const allWines = (req, res) => { | ||||||
|   // TODO add "includeWinners" |   // TODO add "includeWinners" | ||||||
|  |   let { limit } = req.query; | ||||||
|  |  | ||||||
|  |   if (limit && isNaN(limit)) { | ||||||
|  |     return res.status(400).send({ | ||||||
|  |       message: "If limit query parameter is provided it must be a number", | ||||||
|  |       success: false | ||||||
|  |     }); | ||||||
|  |   } else if (!!!isNaN(limit)) { | ||||||
|  |     limit = Number(limit); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   return wineRepository |   return wineRepository | ||||||
|     .allWines() |     .allWines(limit) | ||||||
|     .then(wines => |     .then(wines => | ||||||
|       res.send({ |       res.send({ | ||||||
|         wines: wines, |         wines: wines, | ||||||
|   | |||||||
| @@ -27,8 +27,12 @@ const addWine = async wine => { | |||||||
|   } |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const allWines = () => { | const allWines = (limit = undefined) => { | ||||||
|  |   if (limit) { | ||||||
|  |     return Wine.find().limit(limit); | ||||||
|  |   } else { | ||||||
|     return Wine.find(); |     return Wine.find(); | ||||||
|  |   } | ||||||
| }; | }; | ||||||
|  |  | ||||||
| const wineById = id => { | const wineById = id => { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user