split services / delete dish / mail init
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import express from "express";
|
||||
import { createRestaurant } from "../services/dataPrepServices.js";
|
||||
import {
|
||||
addRestaurantToUser,
|
||||
fetchRestaurant,
|
||||
fetchAllDishesForRestaurant,
|
||||
} from "../services/databaseServices.js";
|
||||
import * as services from "../services/services.js";
|
||||
import Restaurant from "../models/restaurant.js";
|
||||
|
||||
@@ -21,9 +27,10 @@ router.get("/", async (req, res) => {
|
||||
router.post("/", async (req, res) => {
|
||||
try {
|
||||
const token = req.headers["x-auth-token"];
|
||||
services.validateUserToken(token);
|
||||
const restaurant = services.createRestaurant(req);
|
||||
const user = services.validateUserToken(token);
|
||||
const restaurant = createRestaurant(req.body);
|
||||
await restaurant.save();
|
||||
await addRestaurantToUser(user, restaurant);
|
||||
res.sendStatus(201);
|
||||
} catch (error) {
|
||||
services.handleError(error, res);
|
||||
@@ -36,8 +43,8 @@ router.get("/dishes", async (req, res) => {
|
||||
try {
|
||||
const query = services.decodeAndSanitize(req.query.restaurantId);
|
||||
await services.validateRestaurant(query);
|
||||
let restaurant = await services.fetchRestaurant(query);
|
||||
let dishes = await services.fetchAllDishesForRestaurant(restaurant);
|
||||
let restaurant = await fetchRestaurant(query);
|
||||
let dishes = await fetchAllDishesForRestaurant(restaurant);
|
||||
res.send(dishes);
|
||||
} catch (error) {
|
||||
services.handleError(error, res);
|
||||
|
||||
Reference in New Issue
Block a user