From 6b0dc667f4a0ccece85c09052d6de5e1064152e3 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Fri, 23 Aug 2024 15:12:30 +0530 Subject: [PATCH] UPDATE TANK changes --- src/controllers/tanksController.js | 15 ++++++++------- src/routes/tanksRoute.js | 28 +++++++++++++--------------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 0ce4bfa6..22b5be65 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -133,13 +133,14 @@ exports.addTanks = async (req, reply) => { exports.updateTanksInfo = async (req, reply) => { try { - const InstallerId = req.params.InstallerId; - const customerId = req.body.customerId; + const customerId = req.params.customerId; + const tankName = req.query.tankName; const tank = req.body; const { ...updateData } = tank; - const update = await Tank.findOneAndUpdate({ InstallerId:InstallerId,tankName: tankName,customerId:customerId }, updateData, { new: true }); - console.log(update.username) + console.log(tank) + const update = await Tank.findOneAndUpdate({customerId:customerId,tankName: tankName,tankLocation:req.body.tankLocation }, updateData, { new: true }); + //console.log(update.username) //return update; reply.send({ status_code: 200, data: update }); @@ -155,11 +156,11 @@ exports.updateTanksInfo = async (req, reply) => { //delete selected tank exports.deleteTanksInfo = async (req, reply) => { try { - const InstallerId = req.params.InstallerId; - const customerId = req.body.customerId; + const customerId = req.params.customerId; + const tankName = req.query.tankName; const tankLocation = req.body.tankLocation.toLowerCase(); - const tank = await Tank.findOneAndDelete({ InstallerId:InstallerId,tankName: tankName,customerId:customerId,tankLocation:tankLocation }); + const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId,tankLocation:tankLocation }); reply.send({ status_code: 200, data: tank}); // return tank; diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 9ba0bb58..76448fe8 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -53,17 +53,17 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "PUT", - url: "/api/updateTanks/:InstallerId", + url: "/api/updateTanks/:customerId", schema: { tags: ["Install"], summary: "This is for update tank", params: { - required: ["InstallerId"], + required: ["customerId"], type: "object", properties: { - InstallerId: { + customerId: { type: "string", - description: "InstallerId", + description: "customerId", }, }, }, @@ -75,8 +75,8 @@ module.exports = function (fastify, opts, next) { type: "object", // required: ['phone'], properties: { - customerId: { type: "string", default: null }, - tankName: { type: "string", default: null }, + + blockName: { type: "string", default: null }, capacity: { type: "string" }, typeOfWater: { type: "string", default: null }, @@ -94,36 +94,34 @@ module.exports = function (fastify, opts, next) { // fastify.auth([fastify.operatorAuthenticate]), // validationHandler.validatePhoneFormat, // ], - preHandler: fastify.auth([fastify.authenticate]), + // preHandler: fastify.auth([fastify.authenticate]), handler: tanksController.updateTanksInfo, }); fastify.route({ method: "PUT", - url: "/api/deleteTank/:InstallerId", + url: "/api/deleteTank/:customerId", schema: { tags: ["Install"], summary: "This is for delete tank", params: { - required: ["InstallerId"], + required: ["customerId"], type: "object", properties: { - InstallerId: { + customerId: { type: "string", - description: "InstallerId", + description: "customerId", }, }, }, - querystring: { - tankName: {type: 'string'} - }, + body: { type: "object", // required: ['phone'], properties: { - customerId: { type: "string", default: null }, + tankLocation: { type: "string", default: null }, }, },