You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

514 lines
13 KiB

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: {
hardwareId: { type: "string" },
tankName: { type: "string" },
blockName: { type: "string"},
capacity: { type: "string" },
typeOfWater: { type: "string" },
tankLocation: { 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",
3 years ago
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",
3 years ago
url: "/api/deleteTank/:customerId",
schema: {
tags: ["Tank"],
summary: "This is for delete tank",
params: {
3 years ago
required: ["customerId"],
type: "object",
properties: {
3 years ago
customerId: {
type: "string",
3 years ago
description: "customerId",
},
},
},
3 years ago
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.get("/api/getTanks", {
schema: {
tags: ["Tank"],
description: "This is for Get Tank Data",
summary: "This is for to Get Tank Data",
querystring: {
3 years ago
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" },
percentage: { type: "string",default: "100" },
startTime:{ type: "string" },
stopTime:{ 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 cretae IOT Device",
summary: "This is for Create IOT Device.",
body: {
type: "object",
properties: {
hardwareId: { type: "string" },
tankHeight: { type: "string"},
maxLevel: { type: "string" },
minLevel: { type: "string" },
mode: { type: "string" },
},
},
security: [
{
basicAuth: [],
},
],
},
// preHandler: [
// fastify.auth([fastify.operatorAuthenticate]),
// validationHandler.validatePhoneFormat,
// ],
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,
});
next();
}