addded to get edit and pending orders of particluar customer

master^2
Varun 8 months ago
parent d16db83367
commit 3f72d30cc7

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

@ -284,7 +284,7 @@ const orderSchema = new mongoose.Schema({
orderId: { type: String, unique: true, required: true },
customerId: { type: String, required: true },
items: { type: Array, required: true },
estimatedTotal: { type: Number, required: true },
estimatedTotal: { type: String, required: true },
status: { type: String, default: "pending" },
}, { timestamps: true });

@ -1405,6 +1405,22 @@ fastify.put("/api/editOrder", {
handler: storeController.editOrder
});
fastify.get("/api/orders/:customerId", {
schema: {
description: "Get pending and accepted orders for a particular customer",
tags: ["Install"],
summary: "Fetch orders based on customerId",
params: {
type: "object",
properties: {
customerId: { type: "string", description: "Customer ID whose orders need to be fetched" }
},
required: ["customerId"]
}
},
handler: storeController.getOrdersByCustomer
});
fastify.post("/api/editQuotationForSensor/:quatationId", {
schema: {

Loading…
Cancel
Save