diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 6c55f635..d677fdb0 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -2667,7 +2667,7 @@ exports.getOrdersByInstallationId = async (req, reply) => { // Only keep one order per customerId const uniqueOrders = Array.from(uniqueCustomersMap.values()); - // Enrich with customer and sensor info + // Enrich with customer and sensor info, AND update work_status if missing const ordersWithDetails = await Promise.all( uniqueOrders.map(async (order) => { const customer = await User.findOne({ customerId: order.customerId }).lean(); @@ -2678,11 +2678,17 @@ exports.getOrdersByInstallationId = async (req, reply) => { status: "blocked", }).lean(); + // ✅ If missing, update work_status to "active" and save in DB + if (!order.work_status) { + order.work_status = "active"; + await order.save(); // This persists the change to MongoDB + } + return { ...order.toObject(), customer: customer || null, allocated_sensors: allocatedSensors, - work_status: order.work_status || "active" // ✅ Add work_status with default + work_status: order.work_status // Now always persisted }; }) ); @@ -2703,6 +2709,7 @@ exports.getOrdersByInstallationId = async (req, reply) => { + exports.getallocatedsensorstouser= async (req, reply) => { try { const { customerId } = req.params;