From 3ff82be36787282563e2cf1b616b09eb160766b8 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 6 Mar 2025 16:15:32 +0530 Subject: [PATCH 1/2] changes in get based on status of in sensors --- src/controllers/storeController.js | 35 +++++++++++++++++++++++++++--- src/routes/storeRoute.js | 20 +++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 3212bbf8..0d78951f 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1305,7 +1305,7 @@ exports.getSensorsByStatus = async (req, reply) => { try { const { storeId } = req.params; - const statuses = ["pending", "available", "rejected"]; + const statuses = ["pending", "available", "rejected","blocked"]; let result = {}; for (const status of statuses) { @@ -1957,8 +1957,12 @@ exports.updateInstallationId = async (req, reply) => { // Update the order with the new installationId const updatedOrder = await Order.findByIdAndUpdate( _id, - { installationId, updated_at: new Date().toISOString() }, // Also update the timestamp - { new: true } // Return the updated document + { + installationId, + status: "installer_assigned", // Updating the status + updated_at: new Date().toISOString(), // Updating timestamp + }, + { new: true } ); if (!updatedOrder) { @@ -1977,6 +1981,31 @@ exports.updateInstallationId = async (req, reply) => { }; +exports.getPendingOrders = async (req, reply) => { + try { + const pendingOrders = await Order.find({ status: "pending" }); + + if (!pendingOrders.length) { + return reply.send({ + status_code: 200, + message: "No pending orders found", + data: [], + }); + } + + return reply.send({ + status_code: 200, + message: "Pending orders fetched successfully", + data: pendingOrders, + }); + } catch (err) { + console.error("Error fetching pending orders:", err); + return reply.status(500).send({ error: "Internal server error" }); + } +}; + + + exports.handleEstimation = async (req, reply) => { try { const { customerId, items, estimatedTotal, action } = req.body; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index cd9e1a20..976b9028 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1676,6 +1676,26 @@ fastify.put("/api/updateInstallationId/:_id", { }); +fastify.get("/api/getPendingOrders", { + schema: { + tags: ["Install"], + description: "Fetch all orders with status 'pending'", + summary: "Get all pending orders", + response: { + 200: { + type: "object", + properties: { + status_code: { type: "number" }, + message: { type: "string" }, + data: { type: "array", items: { type: "object" } }, + }, + }, + }, + }, + handler: storeController.getPendingOrders, +}); + + fastify.post("/api/cart/hardwareItem", { schema: { description: "To add items to the Hardwarecart", From a09fdbd1ba5d51a26e0f8ab34421e2b3bfa11213 Mon Sep 17 00:00:00 2001 From: Varun Date: Thu, 6 Mar 2025 16:16:09 +0530 Subject: [PATCH 2/2] changes --- src/controllers/storeController.js | 1 + src/routes/storeRoute.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 0d78951f..170ca884 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1301,6 +1301,7 @@ exports.updateSensorQC = async (req, reply) => { + exports.getSensorsByStatus = async (req, reply) => { try { const { storeId } = req.params; diff --git a/src/routes/storeRoute.js b/src/routes/storeRoute.js index 976b9028..dcb61bab 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1203,6 +1203,7 @@ fastify.get("/api/getSensorsByStatus/:storeId", { description: "Store ID", }, }, + }, }, handler: storeController.getSensorsByStatus,