|
|
|
|
@ -1943,3 +1943,34 @@ exports.editOrder = async (req, reply) => {
|
|
|
|
|
return reply.code(500).send({ message: "Failed to update order" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.getOrdersByCustomer = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!customerId) {
|
|
|
|
|
return reply.code(400).send({ message: "customerId is required" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch orders with status 'pending' or 'accepted' for the given customer
|
|
|
|
|
const orders = await Order.find({
|
|
|
|
|
customerId,
|
|
|
|
|
status: { $in: ["pending", "accepted"] }
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (orders.length === 0) {
|
|
|
|
|
return reply.code(404).send({ message: "No orders found for this customer" });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return reply.code(200).send({
|
|
|
|
|
message: "Orders retrieved successfully",
|
|
|
|
|
customerId,
|
|
|
|
|
orders
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error fetching orders:", error);
|
|
|
|
|
return reply.code(500).send({ message: "Failed to fetch orders" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|