|
|
|
@ -2069,6 +2069,7 @@ exports.acceptQuotation = async (req, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getOrdersByStoreId = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { storeId } = req.params;
|
|
|
|
@ -2080,10 +2081,29 @@ exports.getOrdersByStoreId = async (req, reply) => {
|
|
|
|
|
// Fetch orders with the matching storeId
|
|
|
|
|
const orders = await Order.find({ storeId });
|
|
|
|
|
|
|
|
|
|
if (!orders.length) {
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "No orders found for this store",
|
|
|
|
|
data: [],
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch customer details for each order
|
|
|
|
|
const ordersWithCustomerDetails = await Promise.all(
|
|
|
|
|
orders.map(async (order) => {
|
|
|
|
|
const customer = await User.findOne({ customerId: order.customerId }).lean();
|
|
|
|
|
return {
|
|
|
|
|
...order.toObject(),
|
|
|
|
|
customer: customer || null, // Include customer details or null if not found
|
|
|
|
|
};
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
message: "Orders fetched successfully",
|
|
|
|
|
data: orders,
|
|
|
|
|
data: ordersWithCustomerDetails,
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching orders:", err);
|
|
|
|
|