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
|
||||
.orderByWins(includeWines == "true", limit)
|
||||
.then(winners =>
|
||||
|
||||
@@ -3,9 +3,19 @@ const wineRepository = require(path.join(__dirname, "../wine"));
|
||||
|
||||
const allWines = (req, res) => {
|
||||
// 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
|
||||
.allWines()
|
||||
.allWines(limit)
|
||||
.then(wines =>
|
||||
res.send({
|
||||
wines: wines,
|
||||
|
||||
@@ -27,8 +27,12 @@ const addWine = async wine => {
|
||||
}
|
||||
};
|
||||
|
||||
const allWines = () => {
|
||||
return Wine.find();
|
||||
const allWines = (limit = undefined) => {
|
||||
if (limit) {
|
||||
return Wine.find().limit(limit);
|
||||
} else {
|
||||
return Wine.find();
|
||||
}
|
||||
};
|
||||
|
||||
const wineById = id => {
|
||||
|
||||
Reference in New Issue
Block a user