|
|
|
const fastify = require("fastify");
|
|
|
|
const tanksController = require("../controllers/tanksController");
|
|
|
|
const { Tank } = require('../models/tanks')
|
|
|
|
|
|
|
|
module.exports = function (fastify, opts, next) {
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "POST",
|
|
|
|
url: "/api/addTanks/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for cretae New Tank",
|
|
|
|
summary: "This is for Create New Tank.",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
tankhardwareId: { type: "string" },
|
|
|
|
hardwareId: { type: "string" },
|
|
|
|
tankName: { type: "string" },
|
|
|
|
blockName: { type: "string"},
|
|
|
|
capacity: { type: "string" },
|
|
|
|
|
|
|
|
typeOfWater: { type: "string" },
|
|
|
|
waterCapacityPerCm:{ type: "string" },
|
|
|
|
tankLocation: { type: "string" },
|
|
|
|
height:{ type: "string" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.addTanks,
|
|
|
|
// onResponse: (request, reply) => {
|
|
|
|
// validationHandler.sendPhoneVerificationCode(request, reply);
|
|
|
|
// },
|
|
|
|
//onResponse: validationHandler.sendPhoneVerificationCode,
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "PUT",
|
|
|
|
url: "/api/updateTanks/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for update tank",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
querystring: {
|
|
|
|
tankName: {type: 'string'}
|
|
|
|
},
|
|
|
|
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
// required: ['phone'],
|
|
|
|
properties: {
|
|
|
|
|
|
|
|
tankName: { type: "string", default: null },
|
|
|
|
blockName: { type: "string", default: null },
|
|
|
|
capacity: { type: "string" },
|
|
|
|
typeOfWater: { type: "string", default: null },
|
|
|
|
type: { type: "string" },
|
|
|
|
tankLocation: { type: "string", default: null },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
// preHandler: [
|
|
|
|
// fastify.auth([fastify.operatorAuthenticate]),
|
|
|
|
// validationHandler.validatePhoneFormat,
|
|
|
|
// ],
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.updateTanksInfo,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "PUT",
|
|
|
|
url: "/api/deleteTank/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for delete tank",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
querystring: {
|
|
|
|
tankName: {type: 'string'}
|
|
|
|
},
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
// required: ['phone'],
|
|
|
|
properties: {
|
|
|
|
|
|
|
|
|
|
|
|
tankLocation: { type: "string", default: null },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.deleteTanksInfo,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "PUT",
|
|
|
|
url: "/api/getConnectionsInfoOfParticularTank/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is to get Connections Info Of ParticularTank",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
// required: ['phone'],
|
|
|
|
properties: {
|
|
|
|
tankName: {type: 'string'},
|
|
|
|
tankLocation: { type: "string", default: null },
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.getConnectionsInfoOfParticularTank,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.get("/api/getTanks", {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for Get Tank Data",
|
|
|
|
summary: "This is for to Get Tank Data",
|
|
|
|
querystring: {
|
|
|
|
customerId: {type: 'string'}
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
// preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.getTank,
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "PUT",
|
|
|
|
url: "/api/updateTanklevels/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for updating tank levels",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
// querystring: {
|
|
|
|
// tankName: {type: 'string'}
|
|
|
|
// },
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.updateTanklevels,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "GET",
|
|
|
|
url: "/api/getTanklevels/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for getting tank levels",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// querystring: {
|
|
|
|
// tankName: {type: 'string'}
|
|
|
|
// },
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.getTanklevels,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "PUT",
|
|
|
|
url: "/api/motorAction/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for start and stop",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
// required: ['phone'],
|
|
|
|
properties: {
|
|
|
|
|
|
|
|
to: { type: "string", default: null },
|
|
|
|
from: { type: "string", default: null },
|
|
|
|
from_type: { type: "string" },
|
|
|
|
to_type: { type: "string" },
|
|
|
|
action: { type: "string" },
|
|
|
|
startTime:{ type: "string" },
|
|
|
|
threshold_type:{type:"string"},
|
|
|
|
manual_threshold_litres:{type:"string"},
|
|
|
|
manual_threshold_time:{type:"string"},
|
|
|
|
stopTime:{type:"string"},
|
|
|
|
motor_id:{type:"string"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
// preHandler: [
|
|
|
|
// fastify.auth([fastify.operatorAuthenticate]),
|
|
|
|
// validationHandler.validatePhoneFormat,
|
|
|
|
// ],
|
|
|
|
//preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.motorAction,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "GET",
|
|
|
|
url: "/api/consumption/:customerId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for getting consumption",
|
|
|
|
params: {
|
|
|
|
required: ["customerId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
customerId: {
|
|
|
|
type: "string",
|
|
|
|
description: "customerId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// querystring: {
|
|
|
|
// tankName: {type: 'string'}
|
|
|
|
// },
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.consumption,
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "PUT",
|
|
|
|
url: "/api/calculateCapacity",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for calculating the capacity",
|
|
|
|
|
|
|
|
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
// required: ['phone'],
|
|
|
|
properties: {
|
|
|
|
shape: { type: "string", default: null },
|
|
|
|
length: { type: "string", default: null },
|
|
|
|
width: { type: "string", default: null },
|
|
|
|
height: { type: "string" },
|
|
|
|
diameter:{ type: "string" },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
// preHandler: [
|
|
|
|
// fastify.auth([fastify.operatorAuthenticate]),
|
|
|
|
// validationHandler.validatePhoneFormat,
|
|
|
|
// ],
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.calculateCapacity,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "POST",
|
|
|
|
url: "/api/APIWrite",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for creating an IOT Device",
|
|
|
|
summary: "this is to Create IOT Device",
|
|
|
|
body: {
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
hardwareId: { type: "string" },
|
|
|
|
mode: { type: "string" },
|
|
|
|
tanks: {
|
|
|
|
type: "array",
|
|
|
|
items: {
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
tankhardwareId: { type: "string" },
|
|
|
|
tankHeight: { type: "string" },
|
|
|
|
maxLevel: { type: "string" },
|
|
|
|
minLevel: { type: "string" }
|
|
|
|
},
|
|
|
|
required: ["tankhardwareId", "tankHeight", "maxLevel", "minLevel"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
required: ["hardwareId", "mode", "tanks"]
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: []
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
handler: tanksController.IotDevice
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.get("/api/APIRead", {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for Get IOT Data",
|
|
|
|
summary: "This is for to Get IOT Data",
|
|
|
|
querystring: {
|
|
|
|
hardwareId: {type: 'string'}
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
|
|
|
|
//preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.getIotD,
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "GET",
|
|
|
|
url: "/api/calculateTimedifference/:hardwareId",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for calculating the time gap between iot data",
|
|
|
|
params: {
|
|
|
|
required: ["hardwareId"],
|
|
|
|
type: "object",
|
|
|
|
properties: {
|
|
|
|
hardwareId: {
|
|
|
|
type: "string",
|
|
|
|
description: "hardwareId",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// querystring: {
|
|
|
|
// tankName: {type: 'string'}
|
|
|
|
// },
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.getLatestData,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: "GET",
|
|
|
|
url: "/api/checkStatusofIot",
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
summary: "This is for checking the status of iots",
|
|
|
|
|
|
|
|
// querystring: {
|
|
|
|
// tankName: {type: 'string'}
|
|
|
|
// },
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.checkStatusofIot,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: 'GET',
|
|
|
|
url: '/waterlevel-sum',
|
|
|
|
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for water level sum",
|
|
|
|
summary: "This is forwater level sum.",
|
|
|
|
querystring: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
tankLocation: { type: 'string' },
|
|
|
|
typeOfWater: { type: 'string' }
|
|
|
|
},
|
|
|
|
required: ['tankLocation', 'typeOfWater']
|
|
|
|
},
|
|
|
|
response: {
|
|
|
|
200: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
waterlevelSum: { type: 'integer' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
handler: tanksController.totalwaterLevelSum
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.route({
|
|
|
|
method: 'POST',
|
|
|
|
url: '/update-waterlevel',
|
|
|
|
schema: {
|
|
|
|
tags: ['Tank'],
|
|
|
|
description: 'This is for updating waterlevel of a tank based on its IOTtank document',
|
|
|
|
summary: 'This is for updating waterlevel of a tank',
|
|
|
|
body: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
hardwareId: { type: 'string' },
|
|
|
|
},
|
|
|
|
required: ['hardwareId'],
|
|
|
|
},
|
|
|
|
response: {
|
|
|
|
200: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
message: { type: 'string' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
404: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
message: { type: 'string' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
500: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
message: { type: 'string' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
handler: tanksController.startUpdateLoop,
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.get("/api/updatewaterlevelsatmidnight", {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for storing waterlevels in tank at midnight",
|
|
|
|
summary: "This is for storing waterlevels in tank at midnight",
|
|
|
|
querystring: {
|
|
|
|
customerId: {type: 'string'}
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.updatewaterlevelsatmidnight,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.get("/api/deletemotordatarecordsbefore7days", {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for deleting the data before 7 days in motorsdata",
|
|
|
|
summary: "This is for deleting the data before 7 days in motorsdata",
|
|
|
|
querystring: {
|
|
|
|
customerId: {type: 'string'}
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.deletemotordatarecordsbefore7days,
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.get("/api/getTankmotordata", {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is for Get Tank Motor Data",
|
|
|
|
summary: "This is for to Get Tank Motor Data",
|
|
|
|
querystring: {
|
|
|
|
customerId: {type: 'string'}
|
|
|
|
},
|
|
|
|
security: [
|
|
|
|
{
|
|
|
|
basicAuth: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
preHandler: fastify.auth([fastify.authenticate]),
|
|
|
|
handler: tanksController.getTankmotordata,
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.post('/api/motor/write', {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is to Write the motor status from iot",
|
|
|
|
summary: "This is to Write the motor status from iot",
|
|
|
|
body: {
|
|
|
|
type: 'object',
|
|
|
|
required: ['motor_id', 'status'],
|
|
|
|
properties: {
|
|
|
|
|
|
|
|
motor_id: { type: 'string' },
|
|
|
|
status: { type: 'string'},
|
|
|
|
current: { type: 'string' },
|
|
|
|
temp: { type: 'string' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
handler: tanksController.writeMotorStatus
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fastify.get('/api/motor/read', {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is to Read the motor status",
|
|
|
|
summary: "This is to Read the motor status",
|
|
|
|
querystring: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
motor_id: { type: 'string' },
|
|
|
|
|
|
|
|
},
|
|
|
|
// required: ['motor_id'],
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
handler: tanksController.readMotorStatus
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
fastify.get('/api/motor/readMotorIotStatus', {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is to Read the motor status from Iot",
|
|
|
|
summary: "This is to Read the motor status from Iot",
|
|
|
|
querystring: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
motor_id: { type: 'string' },
|
|
|
|
|
|
|
|
},
|
|
|
|
// required: ['motor_id'],
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
handler: tanksController.readMotorStatusFromIot
|
|
|
|
});
|
|
|
|
|
|
|
|
fastify.post('/api/motor/changeMotorStatus', {
|
|
|
|
schema: {
|
|
|
|
tags: ["Tank"],
|
|
|
|
description: "This is to change the motor status",
|
|
|
|
summary: "This is to change the motor status",
|
|
|
|
|
|
|
|
body: {
|
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
motor_id: { type: 'string' },
|
|
|
|
action: { type: 'string' },
|
|
|
|
|
|
|
|
},
|
|
|
|
required: ["motor_id"]
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
handler: tanksController.changeMotorStatus
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// fastify.post('/api/motor/write', {
|
|
|
|
// schema: {
|
|
|
|
// tags: ["Tank"],
|
|
|
|
// description: "This is to Write the motor status",
|
|
|
|
// summary: "This is to Write the motor status",
|
|
|
|
// body: {
|
|
|
|
// type: 'object',
|
|
|
|
// required: ['motor_id', 'status'],
|
|
|
|
// properties: {
|
|
|
|
// motor_id: { type: 'string' },
|
|
|
|
// status: { type: 'string', enum: ['on', 'off'] },
|
|
|
|
// current: { type: 'string' },
|
|
|
|
// temp: { type: 'string' },
|
|
|
|
// },
|
|
|
|
// },
|
|
|
|
// // response: {
|
|
|
|
// // 200: {
|
|
|
|
// // type: 'object',
|
|
|
|
// // properties: {
|
|
|
|
// // // Define your response properties here
|
|
|
|
// // motor_id: { type: 'string' },
|
|
|
|
// // status: { type: 'string' },
|
|
|
|
// // current: { type: 'string' },
|
|
|
|
// // temp: { type: 'string' },
|
|
|
|
// // // Add other properties as needed
|
|
|
|
// // },
|
|
|
|
// // },
|
|
|
|
// // },
|
|
|
|
// },
|
|
|
|
// handler: tanksController.writeMotorStatus
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
// fastify.get('/api/motor/read', {
|
|
|
|
// schema: {
|
|
|
|
// tags: ["Tank"],
|
|
|
|
// description: "This is to Read the motor status",
|
|
|
|
// summary: "This is to Read the motor status",
|
|
|
|
// querystring: {
|
|
|
|
// type: 'object',
|
|
|
|
// properties: {
|
|
|
|
// motor_id: { type: 'string' },
|
|
|
|
// action: { type: 'string', enum: ['1', '2'] },
|
|
|
|
// },
|
|
|
|
// required: ['motor_id', 'action'],
|
|
|
|
// },
|
|
|
|
// // response: {
|
|
|
|
// // 200: {
|
|
|
|
// // type: 'object',
|
|
|
|
// // properties: {
|
|
|
|
// // // Define your response properties here
|
|
|
|
// // motor_id: { type: 'string' },
|
|
|
|
// // motor_status: { type: 'string' },
|
|
|
|
// // motor_speed: { type: 'string' },
|
|
|
|
// // motor_temperature: { type: 'string' },
|
|
|
|
// // // Add other properties as needed
|
|
|
|
// // },
|
|
|
|
// // },
|
|
|
|
// // },
|
|
|
|
// },
|
|
|
|
// handler: tanksController.readMotorStatus
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|