UPDATE TANK changes

master
Bhaskar 1 year ago
parent 1506c839a2
commit 6b0dc667f4

@ -133,13 +133,14 @@ exports.addTanks = async (req, reply) => {
exports.updateTanksInfo = async (req, reply) => { exports.updateTanksInfo = async (req, reply) => {
try { try {
const InstallerId = req.params.InstallerId; const customerId = req.params.customerId;
const customerId = req.body.customerId;
const tankName = req.query.tankName; const tankName = req.query.tankName;
const tank = req.body; const tank = req.body;
const { ...updateData } = tank; const { ...updateData } = tank;
const update = await Tank.findOneAndUpdate({ InstallerId:InstallerId,tankName: tankName,customerId:customerId }, updateData, { new: true }); console.log(tank)
console.log(update.username) const update = await Tank.findOneAndUpdate({customerId:customerId,tankName: tankName,tankLocation:req.body.tankLocation }, updateData, { new: true });
//console.log(update.username)
//return update; //return update;
reply.send({ status_code: 200, data: update }); reply.send({ status_code: 200, data: update });
@ -155,11 +156,11 @@ exports.updateTanksInfo = async (req, reply) => {
//delete selected tank //delete selected tank
exports.deleteTanksInfo = async (req, reply) => { exports.deleteTanksInfo = async (req, reply) => {
try { try {
const InstallerId = req.params.InstallerId; const customerId = req.params.customerId;
const customerId = req.body.customerId;
const tankName = req.query.tankName; const tankName = req.query.tankName;
const tankLocation = req.body.tankLocation.toLowerCase(); 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}); reply.send({ status_code: 200, data: tank});
// return tank; // return tank;

@ -53,17 +53,17 @@ module.exports = function (fastify, opts, next) {
fastify.route({ fastify.route({
method: "PUT", method: "PUT",
url: "/api/updateTanks/:InstallerId", url: "/api/updateTanks/:customerId",
schema: { schema: {
tags: ["Install"], tags: ["Install"],
summary: "This is for update tank", summary: "This is for update tank",
params: { params: {
required: ["InstallerId"], required: ["customerId"],
type: "object", type: "object",
properties: { properties: {
InstallerId: { customerId: {
type: "string", type: "string",
description: "InstallerId", description: "customerId",
}, },
}, },
}, },
@ -75,8 +75,8 @@ module.exports = function (fastify, opts, next) {
type: "object", type: "object",
// required: ['phone'], // required: ['phone'],
properties: { properties: {
customerId: { type: "string", default: null },
tankName: { type: "string", default: null },
blockName: { type: "string", default: null }, blockName: { type: "string", default: null },
capacity: { type: "string" }, capacity: { type: "string" },
typeOfWater: { type: "string", default: null }, typeOfWater: { type: "string", default: null },
@ -94,36 +94,34 @@ module.exports = function (fastify, opts, next) {
// fastify.auth([fastify.operatorAuthenticate]), // fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat, // validationHandler.validatePhoneFormat,
// ], // ],
preHandler: fastify.auth([fastify.authenticate]), // preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.updateTanksInfo, handler: tanksController.updateTanksInfo,
}); });
fastify.route({ fastify.route({
method: "PUT", method: "PUT",
url: "/api/deleteTank/:InstallerId", url: "/api/deleteTank/:customerId",
schema: { schema: {
tags: ["Install"], tags: ["Install"],
summary: "This is for delete tank", summary: "This is for delete tank",
params: { params: {
required: ["InstallerId"], required: ["customerId"],
type: "object", type: "object",
properties: { properties: {
InstallerId: { customerId: {
type: "string", type: "string",
description: "InstallerId", description: "customerId",
}, },
}, },
}, },
querystring: {
tankName: {type: 'string'}
},
body: { body: {
type: "object", type: "object",
// required: ['phone'], // required: ['phone'],
properties: { properties: {
customerId: { type: "string", default: null },
tankLocation: { type: "string", default: null }, tankLocation: { type: "string", default: null },
}, },
}, },

Loading…
Cancel
Save