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
Showing only changes of commit 3f77722f4f - Show all commits

View File

@@ -103,11 +103,25 @@ const lotteryByDate = (req, res) => {
});
};
const sortOptions = ["desc", "asc"];
const allLotteries = (req, res) => {
const isAdmin = req.isAuthenticated();
let { includeWinners, year, sort } = req.query;
return lotteryRepository
.allLotteries(isAdmin)
if (sort !== undefined && !sortOptions.includes(sort)) {
return res.status(400).send({
message: `Sort option must be: '${sortOptions.join(", ")}'`,
success: false
});
} else if (sort === undefined) {
sort = "asc";
}
let allLotteriesFunction = lotteryRepository.allLotteries;
if (includeWinners === "true") {
allLotteriesFunction = lotteryRepository.allLotteriesIncludingWinners;
}
return allLotteriesFunction(sort, year)
.then(lotteries =>
res.send({
lotteries,