From 8f76754911a9d4ea07d107e5b2f463f53df724b1 Mon Sep 17 00:00:00 2001 From: Varun Date: Tue, 4 Mar 2025 17:05:48 +0530 Subject: [PATCH] Added get for orders based on storeId --- src/controllers/storeController.js | 24 ++++++++++++++++++++++++ src/routes/storeRoute.js | 24 ++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 0dc5fedf..bcb33432 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -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" }); + } +}; + diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 791f26c2..93395ccb 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -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(); };