From 49a3f1fe1de46f5de09e064ecfc0b315555dabd8 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 6 Mar 2025 12:54:30 +0530 Subject: [PATCH] changes --- src/controllers/storeController.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 205cb3f2..741fa024 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -2108,7 +2108,7 @@ exports.acceptQuotation = async (req, reply) => { { type: "slave", count: parseInt(slaves || 0) }, { type: "sensor", count: parseInt(sensors || 0) }, ]; - console.log(sensorTypes,"sensortypes") + for (const sensor of sensorTypes) { if (sensor.count > 0) { const stock = await SensorStock.findOne({ storeId, type: sensor.type }); @@ -2120,13 +2120,21 @@ exports.acceptQuotation = async (req, reply) => { let toBlock = Math.min(available, needed); let excessNeeded = needed - toBlock; - // Update Insensors for available sensors if (toBlock > 0) { - await Insensors.updateMany( - { storeId, type: sensor.type, status: "available" }, - { $set: { status: "blocked", customerId } }, - { limit: toBlock } - ); + // Find the required number of available sensors + const availableSensors = await Insensors.find({ storeId, type: sensor.type, status: "available" }) + .limit(toBlock) + .lean(); + + const sensorIds = availableSensors.map(sensor => sensor._id); + + if (sensorIds.length > 0) { + // Update only the found sensors + await Insensors.updateMany( + { _id: { $in: sensorIds } }, + { $set: { status: "blocked", customerId } } + ); + } } // Update SensorStock