From d5dc7272f7fc3185022090a89ceb9d040988c182 Mon Sep 17 00:00:00 2001 From: varun Date: Tue, 21 May 2024 05:06:55 -0400 Subject: [PATCH] automation of motor switch test2 --- src/controllers/tanksController.js | 23 ++++++++++++--- src/routes/tanksRoute.js | 47 ++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 560c43b8..2a795496 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -2323,7 +2323,7 @@ exports.motortemperature = async (req, reply) => { exports.update_auto_mode = async (req, reply) => { try { const customerId = req.params.customerId; - const { motor_id, auto_min_percentage, auto_max_percentage, auto_mode } = req.body; + const { motor_id, auto_mode } = req.body; // Update inputConnections' auto_mode await Tank.updateOne( @@ -2331,9 +2331,25 @@ exports.update_auto_mode = async (req, reply) => { { $set: { "connections.inputConnections.$.auto_mode": auto_mode } } ); + + + reply.send({ status_code: 200, message: "Auto mode and percentages updated successfully." }); + } catch (error) { + throw boom.boomify(error); + } +}; + +exports.update_auto_percentage = async (req, reply) => { + try { + const customerId = req.params.customerId; + const { tankName,tankLocation, auto_min_percentage, auto_max_percentage } = req.body; + + // Update inputConnections' auto_mode + + // Update auto_min_percentage and auto_max_percentage - await Tank.updateMany( - { customerId: customerId }, + await Tank.updateOne( + { customerId: customerId,tankLocation, tankName}, { $set: { "auto_min_percentage": auto_min_percentage, @@ -2347,4 +2363,3 @@ exports.update_auto_mode = async (req, reply) => { throw boom.boomify(error); } }; - diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 6ac3d2bd..6122a18d 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -797,8 +797,7 @@ module.exports = function (fastify, opts, next) { // required: ['phone'], properties: { motor_id: { type: "string", default: null }, - auto_min_percentage: { type: "string", default: null }, - auto_max_percentage: { type: "string", default: null }, + auto_mode: { type: "string", default: null }, }, @@ -818,6 +817,50 @@ module.exports = function (fastify, opts, next) { }); + + + fastify.route({ + method: "PUT", + url: "/api/update_auto_percentage/:customerId", + schema: { + tags: ["Tank"], + summary: "This is for changing auto mode for motor with min and max levels", + params: { + required: ["customerId"], + type: "object", + properties: { + customerId: { + type: "string", + description: "customerId", + }, + }, + }, + + body: { + type: "object", + // required: ['phone'], + properties: { + tankName: { type: "string", default: null }, + auto_min_percentage: { type: "string", default: null }, + auto_max_percentage: { type: "string", default: null }, + tankLocation: { type: "string", default: null }, + + }, + }, + security: [ + { + basicAuth: [], + }, + ], + }, + // preHandler: [ + // fastify.auth([fastify.operatorAuthenticate]), + // validationHandler.validatePhoneFormat, + // ], + //preHandler: fastify.auth([fastify.authenticate]), + handler: tanksController.update_auto_percentage, + }); + next(); }