diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 5937a383..ba2cedd7 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -5,6 +5,11 @@ const fastify = require("fastify")({ logger: true, }); + + + + + exports.addTanks = async (req, reply) => { try { @@ -134,7 +139,7 @@ exports.getTank = async (req, reply) => { // } //}; -exports.getTanklevels = async (req, reply) => { +exports.updateTanklevels = async (req, reply) => { try { const customerId = req.params.customerId; const tank = await Tank.find({customerId}); @@ -167,4 +172,24 @@ exports.getTanklevels = async (req, reply) => { throw boom.boomify(err); } }; + + +exports.getTanklevels = async (req, reply) => { + try { + const customerId = req.params.customerId; + + + const updated_data = await Tank.find({ customerId: customerId }); + + reply.send({ status_code: 200, data: updated_data}); + + + + return { message: 'success' }; +} + + catch (err) { + throw boom.boomify(err); + } +}; diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 7e25bcfd..8fbdc87d 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -142,6 +142,36 @@ module.exports = function (fastify, opts, next) { handler: tanksController.getTank, }); + fastify.route({ + method: "GET", + url: "/api/updateTanklevels/:customerId", + schema: { + tags: ["Tank"], + summary: "This is for updating tank levels", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + // querystring: { + // tankName: {type: 'string'} + // }, + security: [ + { + basicAuth: [], + }, + ], + }, + preHandler: fastify.auth([fastify.authenticate]), + handler: tanksController.updateTanklevels, + }); + + fastify.route({ method: "GET", url: "/api/getTanklevels/:customerId", @@ -171,7 +201,6 @@ module.exports = function (fastify, opts, next) { handler: tanksController.getTanklevels, }); - next();