diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 39dc5cfb..74d83ab6 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -8,7 +8,7 @@ const fastify = require("fastify")({ exports.addTanks = async (req, reply) => { try { - const username = req.params.username + var customerId = req.params.customerId //const username = req.params.username; console.log(req.params); @@ -21,7 +21,7 @@ console.log(req.params); // console.log("This is the reply in the handler after the validations", reply); tankData = { - userName: username, + customerId: customerId, tankName: req.body.tankName, blockName: req.body.blockName, capacity: req.body.capacity, @@ -31,7 +31,7 @@ console.log(req.params); }; var tank_name = req.body.tankName - var i_tank = await Tank.findOne({ tankName: tank_name,userName:username}) + var i_tank = await Tank.findOne({ tankName: tank_name,customerId:customerId}) if(i_tank){ throw new Error('tankname already exists'); } @@ -43,6 +43,7 @@ console.log(req.params); if (checkFormEncoding.isUserFormUrlEncoded) { usertobeInserted = checkFormEncoding.tank; console.log("thsi true url string"); + tank.customerId = usertobeInserted.customerId tank.tankName = usertobeInserted.tankName; tank.blockName = usertobeInserted.blockName; tank.capacity = usertobeInserted.capacity; @@ -66,11 +67,11 @@ console.log(req.params); exports.updateTanksInfo = async (req, reply) => { try { - const username = loginObject.user.username; + const customerId = req.params.customerId; const tankName = req.params.tankName; const tank = req.body; const { ...updateData } = tank; - const update = await Tank.findOneAndUpdate({ tankName: tankName,userName:username, }, updateData, { new: true }); + const update = await Tank.findOneAndUpdate({ tankName: tankName,customerId:customerId, }, updateData, { new: true }); console.log(update.username) //return update; diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index d9db8baa..36b8b50a 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -5,11 +5,21 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "POST", - url: "/api/addTanks", + url: "/api/addTanks/:customerId", schema: { tags: ["Tank"], description: "This is for cretae New Tank", summary: "This is for Create New Tank.", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, body: { type: "object", properties: { @@ -38,10 +48,20 @@ module.exports = function (fastify, opts, next) { fastify.route({ method: "PUT", - url: "/api/updateTanks/:tankName", + url: "/api/updateTanks/:customerId/:tankName", schema: { tags: ["Tank"], summary: "This is for update tank", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, params: { required: ["tankName"], type: "object", @@ -56,6 +76,7 @@ module.exports = function (fastify, opts, next) { type: "object", // required: ['phone'], properties: { + tankName: { type: "string", default: null }, blockName: { type: "string", default: null }, capacity: { type: "string" },