changing auto mode for tank

master
varun 1 year ago
parent e961f3e1e4
commit 750b66d414

@ -1625,4 +1625,31 @@ 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;
// Update inputConnections' auto_mode
await Tank.updateOne(
{ customerId: customerId, "connections.inputConnections.motor_id": motor_id },
{ $set: { "connections.inputConnections.$.auto_mode": auto_mode } }
);
// Update auto_min_percentage and auto_max_percentage
await Tank.updateMany(
{ customerId: customerId },
{
$set: {
"auto_min_percentage": auto_min_percentage,
"auto_max_percentage": auto_max_percentage
}
}
);
reply.send({ status_code: 200, message: "Auto mode and percentages updated successfully." });
} catch (error) {
throw boom.boomify(error);
}
};

@ -36,7 +36,6 @@ const tanksSchema = new mongoose.Schema({
tankhardwareId: { type: String },
hardwareId_type: { type: String },
motor_id:{ type: String ,default: null},
hardwareId_company: { type: String },
customerId: { type: String, default: null },
tankName: { type: String, default: null },
@ -56,6 +55,7 @@ const tanksSchema = new mongoose.Schema({
auto_min_percentage :{ type: String, default: "20" },
auto_max_percentage :{ type: String, default: "80" },
manual_threesold_percentage:{type: String, default: "90"},
connections: {
source: { type: String },
inputConnections: [
@ -65,6 +65,7 @@ const tanksSchema = new mongoose.Schema({
inputismotor: { type: Boolean, },
motor_id:{ type: String ,default: null},
motor_status: { type: String, default: "0" },
auto_mode:{type:String,default:"inactive"},
motor_stop_status: { type: String, default: "1" },
motor_on_type :{ type: String, default: "manual" },

@ -371,6 +371,9 @@ module.exports = function (fastify, opts, next) {
fastify.get("/api/APIRead", {
schema: {
tags: ["Tank"],
@ -731,6 +734,48 @@ module.exports = function (fastify, opts, next) {
// });
fastify.route({
method: "PUT",
url: "/api/update_auto_mode/: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: {
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 },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
//preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.update_auto_mode,
});
next();
}

Loading…
Cancel
Save