|
|
|
|
@ -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
|
|
|
|
|
|