Get all wines with limit parameter.

This commit is contained in:
2021-02-18 22:07:54 +01:00
parent 4ab67877b9
commit 2477f36f96
3 changed files with 26 additions and 3 deletions

View File

@@ -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 =>

View File

@@ -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,

View File

@@ -27,8 +27,12 @@ const addWine = async wine => {
} }
}; };
const allWines = () => { const allWines = (limit = undefined) => {
return Wine.find(); if (limit) {
return Wine.find().limit(limit);
} else {
return Wine.find();
}
}; };
const wineById = id => { const wineById = id => {