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: "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,14 +2120,22 @@ exports.acceptQuotation = async (req, reply) => {
let toBlock = Math.min(available, needed);
let excessNeeded = needed - toBlock;
// Update Insensors for available sensors
if (toBlock > 0) {
// 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(
{ storeId, type: sensor.type, status: "available" },
{ $set: { status: "blocked", customerId } },
{ limit: toBlock }
{ _id: { $in: sensorIds } },
{ $set: { status: "blocked", customerId } }
);
}
}
// Update SensorStock
await SensorStock.updateOne(

Loading…
Cancel
Save