From 57084618c457406320f6215f7baee64c70978ae5 Mon Sep 17 00:00:00 2001 From: Jonasz Bigda Date: Sun, 27 Dec 2020 13:00:55 +0100 Subject: [PATCH] Img route fix (remove whitespaces) / LunchMenu quantities --- routes/routeRestaurant.js | 1 + services/dataPrepServices.js | 14 +++++++++----- services/databaseServices.js | 5 +++-- services/oceanServices.js | 3 ++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/routes/routeRestaurant.js b/routes/routeRestaurant.js index f23c50f..9072ee6 100644 --- a/routes/routeRestaurant.js +++ b/routes/routeRestaurant.js @@ -134,6 +134,7 @@ router.post("/lunch", async (req, res) => { req.body.restaurantId, req.body.setName, req.body.dishId, + req.body.quantity, req.body.action ); res.sendStatus(200); diff --git a/services/dataPrepServices.js b/services/dataPrepServices.js index 94f0da7..57daa55 100644 --- a/services/dataPrepServices.js +++ b/services/dataPrepServices.js @@ -168,11 +168,15 @@ async function createDish(dish, restaurantId, oldDish) { } } -function appendDishToLunchSet(lunchMenu, setName, dishId) { +function appendDishToLunchSet(lunchMenu, setName, dishId, quantity) { const result = lunchMenu.map((lunchSet) => { if (lunchSet.lunchSetName === setName) { let updatedSet = lunchSet; - updatedSet.lunchSetDishes.push(dishId); + let dishToAdd = { + dishId: dishId, + quantity: quantity + } + updatedSet.lunchSetDishes.push(dishToAdd); return updatedSet; } else { return lunchSet; @@ -185,9 +189,9 @@ function removeDishFromLunchSet(lunchMenu, setName, dishId) { const result = lunchMenu.map((lunchSet) => { if (lunchSet.lunchSetName === setName) { let updatedSet = lunchSet; - const dishIndex = updatedSet.lunchSetDishes.indexOf(dishId); - if (dishIndex > -1) { - updatedSet.lunchSetDishes.splice(dishIndex, 1); + const index = updatedSet.lunchSetDishes.findIndex(dish => dish.dishId === dishId); + if (index > -1) { + updatedSet.lunchSetDishes.splice(index, 1); } return updatedSet; } else { diff --git a/services/databaseServices.js b/services/databaseServices.js index 0308296..ec49007 100644 --- a/services/databaseServices.js +++ b/services/databaseServices.js @@ -229,7 +229,7 @@ async function changeLunchMenuSet(restaurantId, action, lunchSet) { } } -async function changeLunchMenu(restaurantId, setName, dishId, action) { +async function changeLunchMenu(restaurantId, setName, dishId, quantity, action) { if (action === "add") { const restaurant = await Restaurant.findById(restaurantId).catch((err) => { throw newError("Nie udało się pobrać restauracji.", 404); @@ -238,7 +238,8 @@ async function changeLunchMenu(restaurantId, setName, dishId, action) { const updatedLunchMenu = appendDishToLunchSet( restaurant.lunchMenu, setName, - dishId + dishId, + quantity ); await Restaurant.findByIdAndUpdate(restaurantId, { $set: { lunchMenu: updatedLunchMenu }, diff --git a/services/oceanServices.js b/services/oceanServices.js index 29bf20e..06aeadc 100644 --- a/services/oceanServices.js +++ b/services/oceanServices.js @@ -65,8 +65,9 @@ function removePrefix(string) { } function makeTempBlobName(originalName) { + const trimmedName = originalName.replace(/\s/g, ''); const identifier = Math.random().toString().replace(/0\./, ""); - return `TEMP_${identifier}-${originalName}`; + return `TEMP_${identifier}-${trimmedName}`; } function setDeleteTempBlobTimer(blobName, minutes) {