diff --git a/src/controllers/storeController.js b/src/controllers/storeController.js index d2eb5972..a59932d8 100644 --- a/src/controllers/storeController.js +++ b/src/controllers/storeController.js @@ -1945,6 +1945,38 @@ exports.getquotationofinstalleranduser = async (req, reply) => { }; +exports.updateInstallationId = async (req, reply) => { + try { + const { orderId } = req.params; + const { installationId } = req.body; + + if (!orderId || !installationId) { + return reply.status(400).send({ error: "orderId and installationId are required" }); + } + + // Update the order with the new installationId + const updatedOrder = await Order.findByIdAndUpdate( + orderId, + { installationId, updated_at: new Date().toISOString() }, // Also update the timestamp + { new: true } // Return the updated document + ); + + if (!updatedOrder) { + return reply.status(404).send({ error: "Order not found" }); + } + + return reply.send({ + status_code: 200, + message: "Installation ID updated successfully", + data: updatedOrder, + }); + } catch (err) { + console.error("Error updating installationId:", 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 ac661a8f..0214016b 100644 --- a/src/routes/storeRoute.js +++ b/src/routes/storeRoute.js @@ -1608,6 +1608,74 @@ fastify.get("/api/getSingleQuotationData/:quotationId", { handler: storeController.getSinleQuotationData, }); + +fastify.put("/api/updateInstallationId/:orderId", { + schema: { + tags: ["Install"], + description: "Update the installationId of an order", + summary: "Update installationId", + params: { + type: "object", + properties: { + orderId: { + type: "string", + description: "Order ID", + }, + }, + required: ["orderId"], + }, + body: { + type: "object", + properties: { + installationId: { + type: "string", + description: "Installation ID to update", + }, + }, + required: ["installationId"], + }, + response: { + 200: { + description: "Installation ID updated successfully", + type: "object", + properties: { + status_code: { type: "number" }, + message: { type: "string" }, + data: { type: "object" }, + }, + }, + 400: { + description: "Bad request", + type: "object", + properties: { + error: { type: "string" }, + }, + }, + 404: { + description: "Order not found", + type: "object", + properties: { + error: { type: "string" }, + }, + }, + 500: { + description: "Internal server error", + type: "object", + properties: { + error: { type: "string" }, + }, + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + handler: storeController.updateInstallationId, +}); + + fastify.post("/api/cart/hardwareItem", { schema: { description: "To add items to the Hardwarecart",