diff --git a/.DS_Store b/.DS_Store index c9149d2..bc6562e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/app/.DS_Store b/app/.DS_Store index 82d4b55..a4b4205 100644 Binary files a/app/.DS_Store and b/app/.DS_Store differ diff --git a/app/controllers/route-path.controller.js b/app/controllers/route-path.controller.js index a37ed5f..9d2b0f8 100644 --- a/app/controllers/route-path.controller.js +++ b/app/controllers/route-path.controller.js @@ -130,13 +130,40 @@ exports.updateRoute = (req, res) => { }); } const id = req.params.id; - RoutePath.findByIdAndUpdate(id, req.body, { useFindAndModify: false }) - .then(data => { - if (!data) { - res.status(404).send({ + + RoutePath.findById(id) + .then((currentRoute) => { + if (!currentRoute) { + return res.status(404).send({ message: `Cannot update Route with id=${id}. Maybe Route was not found!` }); - } else res.send({ success: true, message: "Route was updated successfully." }); + } + + const updatePayload = Object.assign({}, req.body); + delete updatePayload.id; + + // Safety: only allow customer_route_status updates for customers that + // already belong to this specific route id. + if (Array.isArray(updatePayload.route_customer_list) && Array.isArray(currentRoute.route_customer_list)) { + const customerIdsInCurrentRoute = new Set( + currentRoute.route_customer_list.map((c) => `${c.customer_id || c._id || ''}`) + ); + updatePayload.route_customer_list = updatePayload.route_customer_list.map((customer) => { + const customerId = `${customer.customer_id || customer._id || ''}`; + if (customer.customer_route_status && customerId && !customerIdsInCurrentRoute.has(customerId)) { + const sanitizedCustomer = Object.assign({}, customer); + delete sanitizedCustomer.customer_route_status; + return sanitizedCustomer; + } + return customer; + }); + } + + return RoutePath.findByIdAndUpdate(id, updatePayload, { useFindAndModify: false }); + }) + .then((data) => { + if (!data) return; + return res.send({ success: true, message: "Route was updated successfully." }); }) .catch(err => { res.status(500).send({ diff --git a/app/views/asset-manifest.json b/app/views/asset-manifest.json index 1ea4fbe..ed4c725 100644 --- a/app/views/asset-manifest.json +++ b/app/views/asset-manifest.json @@ -1,16 +1,16 @@ { "files": { "main.css": "/static/css/main.46cc12be.css", - "main.js": "/static/js/main.3066488d.js", + "main.js": "/static/js/main.c9552441.js", "static/js/787.c4e7f8f9.chunk.js": "/static/js/787.c4e7f8f9.chunk.js", "static/media/landing.png": "/static/media/landing.d4c6072db7a67dff6a78.png", "index.html": "/index.html", "main.46cc12be.css.map": "/static/css/main.46cc12be.css.map", - "main.3066488d.js.map": "/static/js/main.3066488d.js.map", + "main.c9552441.js.map": "/static/js/main.c9552441.js.map", "787.c4e7f8f9.chunk.js.map": "/static/js/787.c4e7f8f9.chunk.js.map" }, "entrypoints": [ "static/css/main.46cc12be.css", - "static/js/main.3066488d.js" + "static/js/main.c9552441.js" ] } \ No newline at end of file diff --git a/app/views/index.html b/app/views/index.html index 7a9769d..5ecbcf6 100644 --- a/app/views/index.html +++ b/app/views/index.html @@ -1 +1 @@ -
| ".concat(e.label," | ")})).join(""),"\n
|---|
| ".concat(t[e.key]||""," | ")})).join(""),"\n