diff --git a/models/restaurant.js b/models/restaurant.js index 5e0d605..36256eb 100644 --- a/models/restaurant.js +++ b/models/restaurant.js @@ -20,6 +20,19 @@ const restaurantSchema = mongoose.Schema({ type: String, required: true, }, + description: { + type: String, + }, + tags: { + cardPayments: Boolean, + petFriendly: Boolean, + glutenFree: Boolean, + vegan: Boolean, + vegetarian: Boolean, + alcohol: Boolean, + delivery: Boolean, + }, + phone: Number, hidden: Boolean, dishes: [mongoose.Types.ObjectId], }); diff --git a/routes/routeDish.js b/routes/routeDish.js index 6a4bde7..f3adf19 100644 --- a/routes/routeDish.js +++ b/routes/routeDish.js @@ -1,6 +1,7 @@ import express from "express"; import Restaurant from "../models/restaurant.js"; import * as services from "../services/services.js"; +import sanitizer from "string-sanitizer"; import Dish from "../models/dish.js"; var router = express.Router(); diff --git a/routes/routeRestaurant.js b/routes/routeRestaurant.js index f8d9cd6..74623be 100644 --- a/routes/routeRestaurant.js +++ b/routes/routeRestaurant.js @@ -10,17 +10,24 @@ var router = express.Router(); // GET RESTAURANT BY ID router.get("/", (req, res) => { - services.validateRestaurant(req.body.restaurantId, (result) => { - if (!result) { - res.sendStatus(400); - } else { - Restaurant.findById(req.body.restaurantId, (err, data) => { - if (err) { - res.sendStatus(404); - } else res.send(data); - }); - } - }); + if (req.query.restaurantId.length > 0) { + const query = sanitizer.sanitize.keepUnicode( + decodeURI(req.query.restaurantId) + ); + services.validateRestaurant(query, (result) => { + if (!result) { + res.sendStatus(400); + } else { + Restaurant.findById(query, (err, data) => { + if (err) { + res.sendStatus(404); + } else res.send(data); + }); + } + }); + } else { + res.sendStatus(404); + } }); // ADD NEW RESTAURANT @@ -57,30 +64,38 @@ router.post("/", (req, res) => { // GET ALL DISHES FROM A RESTAURANT ID router.get("/dishes", (req, res) => { - services.validateRestaurant(req.body.restaurantId, (result) => { - if (!result) { - res.sendStatus(400); - } else { - Restaurant.findById(req.body.restaurantId, (err, result) => { - if (err) { - res.sendStatus(404); - } else { - const dishesCount = result.dishes.length; - let dishes = []; - result.dishes.forEach((element) => { - Dish.findById(element, (err, result) => { - if (err) { - console.log("ERROR fetching dish"); - } else { - dishes.push(result); - if (dishes.length == dishesCount) res.send(dishes); - } + if (req.query.restaurantId.length > 0) { + const query = sanitizer.sanitize.keepUnicode( + decodeURI(req.query.restaurantId) + ); + + services.validateRestaurant(query, (result) => { + if (!result) { + res.sendStatus(400); + } else { + Restaurant.findById(query, (err, result) => { + if (err) { + res.sendStatus(404); + } else { + const dishesCount = result.dishes.length; + let dishes = []; + result.dishes.forEach((element) => { + Dish.findById(element, (err, result) => { + if (err) { + console.log("ERROR fetching dish"); + } else { + dishes.push(result); + if (dishes.length == dishesCount) res.send(dishes); + } + }); }); - }); - } - }); - } - }); + } + }); + } + }); + } else { + res.sendStatus(404); + } }); export default router; diff --git a/routes/routeSearch.js b/routes/routeSearch.js index c21515b..14708cb 100644 --- a/routes/routeSearch.js +++ b/routes/routeSearch.js @@ -20,7 +20,7 @@ router.get("/", (req, res) => { { hidden: false }, ], }, - "_id name city imgUrl workingHours", + "_id name city imgUrl workingHours description tags phone hidden", (err, results) => { if (err) { res.sendStatus(500);