server v1.0.0

This commit is contained in:
2020-09-16 17:34:24 +02:00
parent a5232e7257
commit 27552e5eb0
13 changed files with 187 additions and 150 deletions

View File

@@ -35,7 +35,7 @@ router.post("/", async (req, res) => {
try {
const token = req.headers["x-auth-token"];
const user = validateUserToken(token);
const restaurant = createRestaurant(req.body);
const restaurant = await createRestaurant(req.body);
await restaurant.save();
await addRestaurantToUser(user, restaurant);
res.sendStatus(201);
@@ -44,6 +44,21 @@ router.post("/", async (req, res) => {
}
});
// UPDATE RESTAURANT
router.put("/", async (req, res) => {
try {
const token = req.headers["x-auth-token"];
const user = validateUserToken(token);
const oldRestaurant = await fetchRestaurant(req.body.restaurantId);
const newRestaurant = await createRestaurant(req.body, oldRestaurant);
await Restaurant.replaceOne({ _id: req.body.restaurantId }, newRestaurant);
res.send("Dane zostały zaktualizowane.");
} catch (error) {
handleError(error, res);
}
});
// GET ALL DISHES FROM A RESTAURANT ID
router.get("/dishes", async (req, res) => {