server 1.0.3

This commit is contained in:
2020-09-19 18:16:50 +02:00
parent 36dd3d8238
commit d7395f5472
8 changed files with 35 additions and 13 deletions

View File

@@ -12,6 +12,7 @@ import {
handleError,
validateUserToken,
verifyRestaurantAccess,
newError,
} from "../services/services.js";
import Restaurant from "../models/restaurant.js";
@@ -35,7 +36,9 @@ router.post("/", async (req, res) => {
try {
const token = req.headers["x-auth-token"];
const user = validateUserToken(token);
const restaurant = await createRestaurant(req.body);
const restaurant = await createRestaurant(req.body).catch((err) => {
throw newError("Nie udało się zapisać zdjęcia.", 500);
});
await restaurant.save();
await addRestaurantToUser(user, restaurant);
res.sendStatus(201);