automation of motor switch test2

master
varun 1 year ago
parent 804f3a134c
commit d5dc7272f7

@ -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);
}
};

@ -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();
}

Loading…
Cancel
Save