server v1.0.4

+ working hours for a whole week
+ dish visibility API
+ categories API
+ lunch menu API
+ updated Readme
This commit is contained in:
2020-09-23 18:41:02 +02:00
parent d7395f5472
commit 3a6a6f4c5c
7 changed files with 194 additions and 23 deletions

View File

@@ -5,6 +5,8 @@ import {
fetchRestaurant,
fetchAllDishesForRestaurant,
removeRestaurant,
changeCategory,
changeLunchMenu,
} from "../services/databaseServices.js";
import {
decodeAndSanitize,
@@ -76,6 +78,44 @@ router.get("/dishes", async (req, res) => {
}
});
// CHANGE CATEGORY
router.post("/category", async (req, res) => {
try {
const token = req.headers["x-auth-token"];
const user = validateUserToken(token);
await validateRestaurant(req.body.restaurantId);
await verifyRestaurantAccess(req.body.restaurantId, user);
await changeCategory(
req.body.restaurantId,
req.body.category,
req.body.action
);
res.send("Kategoria zmieniona pomyślnie");
} catch (error) {
handleError(error, res);
}
});
// CHANGE LUNCH MENU
router.post("/lunch", async (req, res) => {
try {
const token = req.headers["x-auth-token"];
const user = validateUserToken(token);
await validateRestaurant(req.body.restaurantId);
await verifyRestaurantAccess(req.body.restaurantId, user);
await changeLunchMenu(
req.body.restaurantId,
req.body.dishId,
req.body.action
);
res.send("Lunch menu zmienione pomyślnie.");
} catch (error) {
handleError(error, res);
}
});
// DELETE RESTAURANT
router.post("/delete", async (req, res) => {