Feat/controllers - refactor entire backend and new admin interface #75

Merged
KevinMidboe merged 117 commits from feat/controllers into master 2021-02-19 00:19:52 +00:00
3 changed files with 26 additions and 3 deletions
Showing only changes of commit 2477f36f96 - Show all commits

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
.orderByWins(includeWines == "true", limit)
.then(winners =>

View File

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

View File

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