diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 7fa151d8..7d4c920a 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -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" }) diff --git a/src/models/store.js b/src/models/store.js index 6fb72d5a..68348077 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -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 },