changes in accept quotation

master^2
Varun 5 months ago
parent 7bb50ebc20
commit 88e050745e

@ -2321,7 +2321,7 @@ exports.acceptQuotation = async (req, reply) => {
{ $set: { status: "blocked", customerId, connected_to: masterHardwareId } }
);
// Assign each slave a corresponding tank (1-to-1 mapping)
// Assign each slave a corresponding tank
const tanks = masterData.tanks || [];
for (let j = 0; j < availableSlaves.length; j++) {
@ -2356,6 +2356,19 @@ exports.acceptQuotation = async (req, reply) => {
);
}
// ✅ Step 2.5: Update master_connections.hardwareId in Order
const updatedMasterConnections = newOrder.master_connections.map((conn, index) => {
return {
...conn,
hardwareId: blockedMasters[index]?.hardwareId || null,
};
});
await Order.updateOne(
{ _id: newOrder._id },
{ $set: { master_connections: updatedMasterConnections } }
);
// Step 3: Assign Sensors to Slaves
if (parseInt(sensors) > 0 && blockedSlaves.length > 0) {
const availableSensors = await Insensors.find({ storeId, type: "sensor", status: "available" })

@ -605,6 +605,7 @@ const orderSchema = new mongoose.Schema({
master_connections: [
{
master_name: { type: String, default: null },
hardwareId:{ type: String, default: null },
slaves: { type: String, default: null },
location: { type: String, default: null },
googleLocation: { type: String, default: null },

Loading…
Cancel
Save