|
|
|
@ -2190,13 +2190,23 @@ exports.getOrdersByStoreId = async (req, reply) => {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch customer details for each order
|
|
|
|
|
const ordersWithCustomerDetails = await Promise.all(
|
|
|
|
|
// Fetch customer details & allocated sensors for each order
|
|
|
|
|
const ordersWithDetails = await Promise.all(
|
|
|
|
|
orders.map(async (order) => {
|
|
|
|
|
// Fetch customer details
|
|
|
|
|
const customer = await User.findOne({ customerId: order.customerId }).lean();
|
|
|
|
|
|
|
|
|
|
// Fetch allocated sensors for this customer
|
|
|
|
|
const allocatedSensors = await Insensors.find({
|
|
|
|
|
storeId,
|
|
|
|
|
customerId: order.customerId, // Match only sensors allocated to this customer
|
|
|
|
|
status: "blocked", // Only fetch sensors that are allocated (blocked)
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...order.toObject(),
|
|
|
|
|
customer: customer || null, // Include customer details or null if not found
|
|
|
|
|
allocated_sensors: allocatedSensors, // List of allocated sensors
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
@ -2204,7 +2214,7 @@ exports.getOrdersByStoreId = async (req, reply) => {
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Orders fetched successfully",
|
|
|
|
|
data: ordersWithCustomerDetails,
|
|
|
|
|
data: ordersWithDetails,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching orders:", err);
|
|
|
|
|