master^2
Varun 9 months ago
parent f92386ea2a
commit 49a3f1fe1d

@ -2108,7 +2108,7 @@ exports.acceptQuotation = async (req, reply) => {
{ type: "slave", count: parseInt(slaves || 0) }, { type: "slave", count: parseInt(slaves || 0) },
{ type: "sensor", count: parseInt(sensors || 0) }, { type: "sensor", count: parseInt(sensors || 0) },
]; ];
console.log(sensorTypes,"sensortypes")
for (const sensor of sensorTypes) { for (const sensor of sensorTypes) {
if (sensor.count > 0) { if (sensor.count > 0) {
const stock = await SensorStock.findOne({ storeId, type: sensor.type }); 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 toBlock = Math.min(available, needed);
let excessNeeded = needed - toBlock; let excessNeeded = needed - toBlock;
// Update Insensors for available sensors
if (toBlock > 0) { if (toBlock > 0) {
await Insensors.updateMany( // Find the required number of available sensors
{ storeId, type: sensor.type, status: "available" }, const availableSensors = await Insensors.find({ storeId, type: sensor.type, status: "available" })
{ $set: { status: "blocked", customerId } }, .limit(toBlock)
{ 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 // Update SensorStock

Loading…
Cancel
Save