ashok 3 months ago
commit 7db845d510

@ -2667,7 +2667,7 @@ exports.getOrdersByInstallationId = async (req, reply) => {
// Only keep one order per customerId // Only keep one order per customerId
const uniqueOrders = Array.from(uniqueCustomersMap.values()); 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( const ordersWithDetails = await Promise.all(
uniqueOrders.map(async (order) => { uniqueOrders.map(async (order) => {
const customer = await User.findOne({ customerId: order.customerId }).lean(); const customer = await User.findOne({ customerId: order.customerId }).lean();
@ -2678,11 +2678,17 @@ exports.getOrdersByInstallationId = async (req, reply) => {
status: "blocked", status: "blocked",
}).lean(); }).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 { return {
...order.toObject(), ...order.toObject(),
customer: customer || null, customer: customer || null,
allocated_sensors: allocatedSensors, 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) => { exports.getallocatedsensorstouser= async (req, reply) => {
try { try {
const { customerId } = req.params; const { customerId } = req.params;

Loading…
Cancel
Save