From 4f560d6a61dade7f2922d81fa8d573c79c6a0a9b Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 9 Jul 2025 20:27:05 +0530 Subject: [PATCH] work_status added --- src/controllers/storeController.js | 63 ++++++++++++++++++++++++++++++ src/models/store.js | 1 + 2 files changed, 64 insertions(+) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 3fa1ad41..6c55f635 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -2574,6 +2574,68 @@ exports.getOrdersByStoreId = async (req, reply) => { // } // }; +// exports.getOrdersByInstallationId = async (req, reply) => { +// try { +// const { installationId } = req.params; + +// if (!installationId) { +// return reply.status(400).send({ error: "installationId is required" }); +// } + +// // Fetch orders with the matching installationId +// const orders = await Order.find({ installationId }); + +// if (!orders.length) { +// return reply.send({ +// status_code: 200, +// message: "No orders found for this installation", +// data: [], +// }); +// } + +// const uniqueCustomersMap = new Map(); + +// // Build unique customerId-based map +// for (const order of orders) { +// if (!uniqueCustomersMap.has(order.customerId)) { +// uniqueCustomersMap.set(order.customerId, order); +// } +// } + +// // Only keep one order per customerId +// const uniqueOrders = Array.from(uniqueCustomersMap.values()); + +// // Enrich with customer and sensor info +// const ordersWithDetails = await Promise.all( +// uniqueOrders.map(async (order) => { +// const customer = await User.findOne({ customerId: order.customerId }).lean(); + +// const allocatedSensors = await Insensors.find({ +// storeId: order.storeId, +// customerId: order.customerId, +// status: "blocked", +// }).lean(); + +// return { +// ...order.toObject(), +// customer: customer || null, +// allocated_sensors: allocatedSensors, +// }; +// }) +// ); + +// return reply.send({ +// status_code: 200, +// message: "Orders fetched successfully", +// data: ordersWithDetails, +// }); + +// } catch (err) { +// console.error("Error fetching orders:", err); +// return reply.status(500).send({ error: "Internal server error" }); +// } +// }; + exports.getOrdersByInstallationId = async (req, reply) => { try { const { installationId } = req.params; @@ -2620,6 +2682,7 @@ exports.getOrdersByInstallationId = async (req, reply) => { ...order.toObject(), customer: customer || null, allocated_sensors: allocatedSensors, + work_status: order.work_status || "active" // ✅ Add work_status with default }; }) ); diff --git a/src/models/store.js b/src/models/store.js index 6abacc91..9f9c1288 100644 --- a/src/models/store.js +++ b/src/models/store.js @@ -843,6 +843,7 @@ const orderSchema = new mongoose.Schema({ qutation_total_price: { type: String, default: null }, type: { type: String, default: null }, status: { type: String, default: "pending" }, + work_status: { type: String, enum: ['active', 'pending', 'complete'], default: 'active' }, quatation_status: { type: String, default: "pending" }, });