diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index 3212bbf8..170ca884 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1301,11 +1301,12 @@ exports.updateSensorQC = async (req, reply) => { + 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 +1958,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 +1982,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..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, @@ -1676,6 +1677,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",