Added get for orders based on storeId

master^2
Varun 8 months ago
parent e66c69418e
commit 8f76754911

@ -2066,3 +2066,27 @@ exports.acceptQuotation = async (req, reply) => {
return reply.status(500).send({ error: "Internal server error" });
}
};
exports.getOrdersByStoreId = async (req, reply) => {
try {
const { storeId } = req.params;
if (!storeId) {
return reply.status(400).send({ error: "storeId is required" });
}
// Fetch orders with the matching storeId
const orders = await Order.find({ storeId });
return reply.send({
status_code: 200,
message: "Orders fetched successfully",
data: orders,
});
} catch (err) {
console.error("Error fetching orders:", err);
return reply.status(500).send({ error: "Internal server error" });
}
};

@ -1683,5 +1683,29 @@ fastify.post("/api/acceptquotation/:quotationId", {
// preHandler: fastify.auth([fastify.authenticate]), // Uncomment if authentication is needed
handler: storeController.acceptQuotation,
});
fastify.get("/api/ordersofstore/:storeId", {
schema: {
tags: ["Install"],
description: "Fetches orders based on storeId",
summary: "Get orders by storeId",
params: {
type: "object",
properties: {
storeId: { type: "string" },
},
required: ["storeId"],
},
security: [
{
basicAuth: [],
},
],
},
handler: storeController.getOrdersByStoreId,
});
next();
};

Loading…
Cancel
Save