varun 3 years ago
parent 69b0b7d303
commit 440f2a02f7

@ -67,8 +67,8 @@ console.log(req.params);
exports.updateTanksInfo = async (req, reply) => { exports.updateTanksInfo = async (req, reply) => {
try { try {
const customerId = req.params.customerId; var customerId = req.params.customerId;
const tankName = req.params.tankName; var tankName = req.query.tankName;
const tank = req.body; const tank = req.body;
const { ...updateData } = tank; const { ...updateData } = tank;
const update = await Tank.findOneAndUpdate({ tankName: tankName,customerId:customerId, }, updateData, { new: true }); const update = await Tank.findOneAndUpdate({ tankName: tankName,customerId:customerId, }, updateData, { new: true });
@ -87,9 +87,9 @@ exports.updateTanksInfo = async (req, reply) => {
//delete selected tank //delete selected tank
exports.deleteTanksInfo = async (req, reply) => { exports.deleteTanksInfo = async (req, reply) => {
try { try {
const username = loginObject.user.username; var customerId = req.params.customerId;
const tankName = req.params.tankName; var tankName = req.query.tankName;
const tank = await Tank.findOneAndDelete({ tankName: tankName,userName:username }); const tank = await Tank.findOneAndDelete({ tankName: tankName,customerId:customerId });
reply.send({ status_code: 200, data: tank}); reply.send({ status_code: 200, data: tank});
// return tank; // return tank;
@ -101,7 +101,7 @@ exports.deleteTanksInfo = async (req, reply) => {
//get tanks data by passing username //get tanks data by passing username
exports.getTank = async (req, reply) => { exports.getTank = async (req, reply) => {
try { try {
await Tank.find({userName: req.query.userName}) await Tank.find({customerId: req.query.customerId})
.exec() .exec()
.then((docs) => { .then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length }); reply.send({ status_code: 200, data: docs, count: docs.length });

@ -48,7 +48,7 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "PUT", method: "PUT",
url: "/api/updateTanks/:customerId/:tankName", url: "/api/updateTanks/:customerId",
schema: { schema: {
tags: ["Tank"], tags: ["Tank"],
summary: "This is for update tank", summary: "This is for update tank",
@ -96,20 +96,23 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "PUT", method: "PUT",
url: "/api/deleteTank/:tankName", url: "/api/deleteTank/:customerId",
schema: { schema: {
tags: ["Tank"], tags: ["Tank"],
summary: "This is for delete tank", summary: "This is for delete tank",
params: { params: {
required: ["tankName"], required: ["customerId"],
type: "object", type: "object",
properties: { properties: {
tankName: { customerId: {
type: "string", type: "string",
description: "tankName", description: "customerId",
}, },
}, },
}, },
querystring: {
tankName: {type: 'string'}
},
security: [ security: [
{ {
basicAuth: [], basicAuth: [],
@ -127,7 +130,7 @@ module.exports = function (fastify, opts, next) {
description: "This is for Get Tank Data", description: "This is for Get Tank Data",
summary: "This is for to Get Tank Data", summary: "This is for to Get Tank Data",
querystring: { querystring: {
userName: {type: 'string'} customerId: {type: 'string'}
}, },
security: [ security: [
{ {

Loading…
Cancel
Save