Img route fix (remove whitespaces) / LunchMenu quantities

This commit is contained in:
2020-12-27 13:00:55 +01:00
parent 08960ff514
commit 57084618c4
4 changed files with 15 additions and 8 deletions

View File

@@ -134,6 +134,7 @@ router.post("/lunch", async (req, res) => {
req.body.restaurantId, req.body.restaurantId,
req.body.setName, req.body.setName,
req.body.dishId, req.body.dishId,
req.body.quantity,
req.body.action req.body.action
); );
res.sendStatus(200); res.sendStatus(200);

View File

@@ -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) => { const result = lunchMenu.map((lunchSet) => {
if (lunchSet.lunchSetName === setName) { if (lunchSet.lunchSetName === setName) {
let updatedSet = lunchSet; let updatedSet = lunchSet;
updatedSet.lunchSetDishes.push(dishId); let dishToAdd = {
dishId: dishId,
quantity: quantity
}
updatedSet.lunchSetDishes.push(dishToAdd);
return updatedSet; return updatedSet;
} else { } else {
return lunchSet; return lunchSet;
@@ -185,9 +189,9 @@ function removeDishFromLunchSet(lunchMenu, setName, dishId) {
const result = lunchMenu.map((lunchSet) => { const result = lunchMenu.map((lunchSet) => {
if (lunchSet.lunchSetName === setName) { if (lunchSet.lunchSetName === setName) {
let updatedSet = lunchSet; let updatedSet = lunchSet;
const dishIndex = updatedSet.lunchSetDishes.indexOf(dishId); const index = updatedSet.lunchSetDishes.findIndex(dish => dish.dishId === dishId);
if (dishIndex > -1) { if (index > -1) {
updatedSet.lunchSetDishes.splice(dishIndex, 1); updatedSet.lunchSetDishes.splice(index, 1);
} }
return updatedSet; return updatedSet;
} else { } else {

View File

@@ -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") { if (action === "add") {
const restaurant = await Restaurant.findById(restaurantId).catch((err) => { const restaurant = await Restaurant.findById(restaurantId).catch((err) => {
throw newError("Nie udało się pobrać restauracji.", 404); throw newError("Nie udało się pobrać restauracji.", 404);
@@ -238,7 +238,8 @@ async function changeLunchMenu(restaurantId, setName, dishId, action) {
const updatedLunchMenu = appendDishToLunchSet( const updatedLunchMenu = appendDishToLunchSet(
restaurant.lunchMenu, restaurant.lunchMenu,
setName, setName,
dishId dishId,
quantity
); );
await Restaurant.findByIdAndUpdate(restaurantId, { await Restaurant.findByIdAndUpdate(restaurantId, {
$set: { lunchMenu: updatedLunchMenu }, $set: { lunchMenu: updatedLunchMenu },

View File

@@ -65,8 +65,9 @@ function removePrefix(string) {
} }
function makeTempBlobName(originalName) { function makeTempBlobName(originalName) {
const trimmedName = originalName.replace(/\s/g, '');
const identifier = Math.random().toString().replace(/0\./, ""); const identifier = Math.random().toString().replace(/0\./, "");
return `TEMP_${identifier}-${originalName}`; return `TEMP_${identifier}-${trimmedName}`;
} }
function setDeleteTempBlobTimer(blobName, minutes) { function setDeleteTempBlobTimer(blobName, minutes) {