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
2 changed files with 27 additions and 2 deletions
Showing only changes of commit 4bd3b688e9 - Show all commits

View File

@@ -27,7 +27,8 @@ router.get("/requests", setAdminHeaderIfAuthenticated, requestController.allRequ
router.post("/request", requestController.addRequest);
router.delete("/request/:id", mustBeAuthenticated, requestController.deleteRequest);
// router.get("/wines", wineController.all); // sort = by-date, by-name, by-occurences
router.get("/wines", wineController.allWines); // sort = by-date, by-name, by-occurences
router.get("/wine/:id", wineController.wineById); // sort = by-date, by-name, by-occurences
// router.update("/wine/:id", mustBeAuthenticated, wineController.update);
router.get("/history", historyController.all);

View File

@@ -1,6 +1,8 @@
const path = require("path");
const Wine = require(path.join(__dirname, "/schemas/Wine"));
const { WineNotFound } = require(path.join(__dirname, "/vinlottisErrors"));
const addWine = async wine => {
let existingWine = await Wine.findOne({ name: wine.name, id: wine.id, year: wine.year });
@@ -29,7 +31,29 @@ const allWines = () => {
return Wine.find();
};
const wineById = id => {
return Wine.findOne({ _id: id }).then(wine => {
if (wine == null) {
throw new WineNotFound();
}
return wine;
});
};
const findWine = wine => {
return Wine.findOne({ name: wine.name, id: wine.id, year: wine.year }).then(wine => {
if (wine == null) {
throw new WineNotFound();
}
return wine;
});
};
module.exports = {
addWine,
allWines
allWines,
wineById,
findWine
};