fixes
This commit is contained in:
@@ -70,6 +70,14 @@ const dishSchema = mongoose.Schema({
|
|||||||
kCal: String,
|
kCal: String,
|
||||||
vegan: Boolean,
|
vegan: Boolean,
|
||||||
vegetarian: Boolean,
|
vegetarian: Boolean,
|
||||||
|
photos: [mongoose.Types.ObjectId],
|
||||||
|
ratings: [
|
||||||
|
{
|
||||||
|
id: mongoose.Types.ObjectId,
|
||||||
|
rate: Number,
|
||||||
|
owner: mongoose.Types.ObjectId
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = mongoose.model("Dish", dishSchema);
|
module.exports = mongoose.model("Dish", dishSchema);
|
||||||
|
|||||||
@@ -127,6 +127,13 @@ const restaurantSchema = mongoose.Schema({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
dishes: [mongoose.Types.ObjectId],
|
dishes: [mongoose.Types.ObjectId],
|
||||||
|
ratings: [
|
||||||
|
{
|
||||||
|
rate: Number,
|
||||||
|
owner: mongoose.Types.ObjectId,
|
||||||
|
id: mongoose.Types.ObjectId
|
||||||
|
}
|
||||||
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = mongoose.model("Restaurant", restaurantSchema);
|
module.exports = mongoose.model("Restaurant", restaurantSchema);
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ router.post("/lunchSet", async (req, res) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// CHANGE LUNCH SET ITEM
|
||||||
|
|
||||||
router.post("/lunch", async (req, res) => {
|
router.post("/lunch", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const token = req.headers["x-auth-token"];
|
const token = req.headers["x-auth-token"];
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ async function createDish(dish, restaurantId, oldDish) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function appendDishToLunchSet(lunchMenu, setName, dishId, quantity) {
|
function appendDishToLunchSet(lunchMenu, setName, dishId, quantity) {
|
||||||
|
console.log("append called")
|
||||||
const result = lunchMenu.map((lunchSet) => {
|
const result = lunchMenu.map((lunchSet) => {
|
||||||
if (lunchSet.lunchSetName === setName) {
|
if (lunchSet.lunchSetName === setName) {
|
||||||
let updatedSet = lunchSet;
|
let updatedSet = lunchSet;
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ const Dish = require("../models/dish.js");
|
|||||||
const User = require("../models/users.js");
|
const User = require("../models/users.js");
|
||||||
const Payments = require("../models/payments.js");
|
const Payments = require("../models/payments.js");
|
||||||
const { deleteImage } = require("./oceanServices.js");
|
const { deleteImage } = require("./oceanServices.js");
|
||||||
const {
|
|
||||||
appendDishToLunchSet,
|
|
||||||
removeDishFromLunchSet,
|
|
||||||
} = require("./dataPrepServices.js");
|
|
||||||
const { newError } = require("./services.js");
|
const { newError } = require("./services.js");
|
||||||
const mongoose = require("mongoose");
|
const mongoose = require("mongoose");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
@@ -229,6 +225,42 @@ async function changeLunchMenuSet(restaurantId, action, lunchSet) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function appendDishToLunchSet(lunchMenu, setName, dishId, quantity) {
|
||||||
|
const result = lunchMenu.map((lunchSet) => {
|
||||||
|
if (lunchSet.lunchSetName === setName) {
|
||||||
|
let updatedSet = lunchSet;
|
||||||
|
let dishToAdd = {
|
||||||
|
dishId: dishId,
|
||||||
|
quantity: quantity
|
||||||
|
}
|
||||||
|
updatedSet.lunchSetDishes.push(dishToAdd);
|
||||||
|
return updatedSet;
|
||||||
|
} else {
|
||||||
|
return lunchSet;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeDishFromLunchSet(lunchMenu, setName, dishId) {
|
||||||
|
console.log("remove called")
|
||||||
|
const result = lunchMenu.map((lunchSet) => {
|
||||||
|
if (lunchSet.lunchSetName === setName) {
|
||||||
|
let updatedSet = lunchSet;
|
||||||
|
const index = updatedSet.lunchSetDishes.findIndex((dish) => {
|
||||||
|
return dish.dishId.toString() === dishId.toString();
|
||||||
|
});
|
||||||
|
if (index > -1) {
|
||||||
|
updatedSet.lunchSetDishes.splice(index, 1);
|
||||||
|
}
|
||||||
|
return updatedSet;
|
||||||
|
} else {
|
||||||
|
return lunchSet;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
async function changeLunchMenu(restaurantId, setName, dishId, quantity, action) {
|
async function changeLunchMenu(restaurantId, setName, dishId, quantity, action) {
|
||||||
if (action === "add") {
|
if (action === "add") {
|
||||||
const restaurant = await Restaurant.findById(restaurantId).catch((err) => {
|
const restaurant = await Restaurant.findById(restaurantId).catch((err) => {
|
||||||
@@ -269,16 +301,11 @@ async function fetchRestaurant(id) {
|
|||||||
const data = await Restaurant.findById(id).catch((e) => {
|
const data = await Restaurant.findById(id).catch((e) => {
|
||||||
throw newError("Nie udało się pobrać restauracji.", 500);
|
throw newError("Nie udało się pobrać restauracji.", 500);
|
||||||
});
|
});
|
||||||
console.log("fetched restaurant");
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchMultipleRestaurants(idArray) {
|
async function fetchMultipleRestaurants(idArray) {
|
||||||
let data = [];
|
let data = await Restaurant.find().where('_id').in(idArray).exec();
|
||||||
for (const id of idArray) {
|
|
||||||
let response = await fetchRestaurant(id);
|
|
||||||
data.push(response);
|
|
||||||
}
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user