ashok 3 months ago
commit 572bd58430

@ -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
};
})
);

@ -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" },
});

Loading…
Cancel
Save