From d783185e696ef7ff327d26ed7cc0921fc45795c2 Mon Sep 17 00:00:00 2001 From: varun Date: Mon, 5 Aug 2024 02:26:50 -0400 Subject: [PATCH] create and get bores for installer --- src/controllers/tankersController.js | 17 ++++++++++ src/controllers/tanksController.js | 34 ++++++++++++++----- src/routes/tankersRoute.js | 18 ++++++++++ src/routes/tanksRoute.js | 49 ++++++++++++++++++++-------- 4 files changed, 96 insertions(+), 22 deletions(-) diff --git a/src/controllers/tankersController.js b/src/controllers/tankersController.js index 29d31b05..8f4c1082 100644 --- a/src/controllers/tankersController.js +++ b/src/controllers/tankersController.js @@ -452,6 +452,23 @@ exports.getBores = async (req, reply) => { }; +exports.getBoresbyInstaller = async (req, reply) => { + try { + await Bore.find({InstallerId: req.query.InstallerId}) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + .catch((err) => { + console.log(err); + reply.send({ error: err }); + }); + } catch (err) { + throw boom.boomify(err); + } +}; + + exports.deleteBoresInfo = async (req, reply) => { try { diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index e556f4be..fe512dbe 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -134,11 +134,12 @@ exports.addTanks = async (req, reply) => { exports.updateTanksInfo = async (req, reply) => { try { - var customerId = req.params.customerId; - var tankName = req.query.tankName; + const InstallerId = req.params.InstallerId; + const customerId = req.body.customerId; + const tankName = req.query.tankName; const tank = req.body; const { ...updateData } = tank; - const update = await Tank.findOneAndUpdate({ tankName: tankName,customerId:customerId, }, updateData, { new: true }); + const update = await Tank.findOneAndUpdate({ InstallerId:InstallerId,tankName: tankName,customerId:customerId }, updateData, { new: true }); console.log(update.username) //return update; @@ -155,10 +156,11 @@ exports.updateTanksInfo = async (req, reply) => { //delete selected tank exports.deleteTanksInfo = async (req, reply) => { try { - const customerId = req.params.customerId; + const InstallerId = req.params.InstallerId; + const customerId = req.body.customerId; const tankName = req.query.tankName; const tankLocation = req.body.tankLocation.toLowerCase(); - const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId,tankLocation:tankLocation }); + const tank = await Tank.findOneAndDelete({ InstallerId:InstallerId,tankName: tankName,customerId:customerId,tankLocation:tankLocation }); reply.send({ status_code: 200, data: tank}); // return tank; @@ -170,13 +172,15 @@ exports.deleteTanksInfo = async (req, reply) => { exports.getConnectionsInfoOfParticularTank = async (req, reply) => { try { - const customerId = req.params.customerId; + const InstallerId = req.params.InstallerId; + const customerId = req.body.customerId; const tankName = req.body.tankName; const tankLocation = req.body.tankLocation.toLowerCase(); console.log(customerId, tankName, tankLocation); // Find the specific tank const mainTank = await Tank.findOne({ + InstallerId:InstallerId, tankName: tankName, customerId: customerId, tankLocation: tankLocation @@ -212,7 +216,21 @@ exports.getTank = async (req, reply) => { } }; - +exports.getTanksofParticularInstaller = async (req, reply) => { + try { + await Tank.find({InstallerId: req.query.InstallerId}) + .exec() + .then((docs) => { + reply.send({ status_code: 200, data: docs, count: docs.length }); + }) + .catch((err) => { + console.log(err); + reply.send({ error: err }); + }); + } catch (err) { + throw boom.boomify(err); + } +}; //exports.getTanklevels = async (req, reply) => { // try { // const customerId = req.params.customerId; @@ -1170,7 +1188,7 @@ exports.motorAction = async (req, reply) => { supplier_type: req.body.from_type, receiver_type: req.body.to_type, startTime: req.body.startTime, - receiverwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10) + receiverInitialwaterlevel:parseInt(receiver_tank_info7.waterlevel, 10) }); await newMotorData.save(); // If threshold type is percentage, calculate percentage threshold diff --git a/src/routes/tankersRoute.js b/src/routes/tankersRoute.js index 6e934177..1c7694ee 100644 --- a/src/routes/tankersRoute.js +++ b/src/routes/tankersRoute.js @@ -384,6 +384,24 @@ module.exports = function (fastify, opts, next) { handler: tankersController.getBores, }); + fastify.get("/api/getBoresbyInstaller", { + schema: { + tags: ["Tank"], + description: "This is for Get Bore Data of Installer", + summary: "This is for to Get Bore Data of installer", + querystring: { + InstallerId: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tankersController.getBoresbyInstaller, + }); + fastify.route({ method: "PUT", url: "/api/deleteBore/:customerId", diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 8b77c595..368bc6d2 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/:customerId", + url: "/api/updateTanks/:InstallerId", schema: { tags: ["Tank"], summary: "This is for update tank", params: { - required: ["customerId"], + required: ["InstallerId"], type: "object", properties: { - customerId: { + InstallerId: { type: "string", - description: "customerId", + description: "InstallerId", }, }, }, @@ -75,7 +75,7 @@ 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" }, @@ -101,17 +101,17 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "PUT", - url: "/api/deleteTank/:customerId", + url: "/api/deleteTank/:InstallerId", schema: { tags: ["Tank"], summary: "This is for delete tank", params: { - required: ["customerId"], + required: ["InstallerId"], type: "object", properties: { - customerId: { + InstallerId: { type: "string", - description: "customerId", + description: "InstallerId", }, }, }, @@ -123,7 +123,7 @@ module.exports = function (fastify, opts, next) { // required: ['phone'], properties: { - + customerId: { type: "string", default: null }, tankLocation: { type: "string", default: null }, }, }, @@ -140,17 +140,17 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "PUT", - url: "/api/getConnectionsInfoOfParticularTank/:customerId", + url: "/api/getConnectionsInfoOfParticularTank/:InstallerId", schema: { tags: ["Tank"], summary: "This is to get Connections Info Of ParticularTank", params: { - required: ["customerId"], + required: ["InstallerId"], type: "object", properties: { - customerId: { + InstallerId: { type: "string", - description: "customerId", + description: "InstallerId", }, }, }, @@ -159,6 +159,7 @@ module.exports = function (fastify, opts, next) { type: "object", // required: ['phone'], properties: { + customerId: { type: "string", default: null }, tankName: {type: 'string'}, tankLocation: { type: "string", default: null }, @@ -182,6 +183,7 @@ module.exports = function (fastify, opts, next) { tags: ["Tank"], description: "This is to Get Tank Data", summary: "This is to Get Tank Data", + querystring: { customerId: {type: 'string'} }, @@ -194,6 +196,25 @@ module.exports = function (fastify, opts, next) { // preHandler: fastify.auth([fastify.authenticate]), handler: tanksController.getTank, }); + + fastify.get("/api/getTanksofParticularInstaller", { + schema: { + tags: ["Tank"], + description: "This is to Get Tank Data of Installer", + summary: "This is to Get Tank Data of Installer", + + querystring: { + InstallerId: {type: 'string'} + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: fastify.auth([fastify.authenticate]), + handler: tanksController.getTanksofParticularInstaller, + }); fastify.route({ method: "PUT",