From 3ce216104d1459ba5132cac5df43d8216d474077 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Mon, 16 Oct 2023 08:01:44 +0000 Subject: [PATCH 01/13] Update 'src/controllers/userController.js' --- src/controllers/userController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/userController.js b/src/controllers/userController.js index 3a5030f7..013960e8 100644 --- a/src/controllers/userController.js +++ b/src/controllers/userController.js @@ -2,7 +2,7 @@ // logger: true, // }); -const axios = require('axios'); +//const axios = require('axios'); const bcrypt = require("bcrypt"); const saltRounds = 10; const libphonenumberjs = require("libphonenumber-js"); From 81639553d9114af17db1b9d2c53678d8de942d0a Mon Sep 17 00:00:00 2001 From: gitadmin Date: Mon, 16 Oct 2023 08:52:40 +0000 Subject: [PATCH 02/13] Update 'src/index.js' --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index c40a2383..e9df1586 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ const userController = require("./controllers/userController"); const { User,Counter, generateBookingId,resetCounter,generateCustomerId,ProfilePicture} = require('./models/User') -const tanksController = require("./controllers/tanksController"); +//const tanksController = require("./controllers/tanksController"); const tankersController = require("./controllers/tankersController.js"); const createConnectionController = require("./controllers/createConnectionController"); const cors = require("cors"); From 6bb9105cf905e78913047d0bd5cdf287529d402d Mon Sep 17 00:00:00 2001 From: gitadmin Date: Mon, 16 Oct 2023 09:25:16 +0000 Subject: [PATCH 03/13] Update 'src/controllers/tanksController.js' --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 26841904..88fb50f6 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1346,7 +1346,7 @@ exports.totalwaterLevelSum = async (request, reply) => { } ]); - const result = waterlevelSum[0]?.totalWaterlevel ?? 0; + const result = waterlevelSum[0]?totalWaterlevel : 0 reply.send({ waterlevelSum: result }); } From 62ed3b917f1595bc92c211b7f0cada21919aebbc Mon Sep 17 00:00:00 2001 From: gitadmin Date: Mon, 16 Oct 2023 09:29:36 +0000 Subject: [PATCH 04/13] Update 'src/config/config.js' --- src/config/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config.js b/src/config/config.js index 0b1f4ff5..406357d5 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -30,7 +30,7 @@ const defaultDatabase = "arminta-tank-db"; async function dbConnection() { try { - db.connect(databaseURLNew, { user: "armintatankdbuser", pass: "armintatank1" , useUnifiedTopology: true, }); + db.connect(databaseURLNew); // db.connect(databaseURLNew) db.connection.on("connected", function () { console.log( From 1c6a376185bf1a728784bf407ac0f3ffc6a95320 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Mon, 16 Oct 2023 09:43:39 +0000 Subject: [PATCH 05/13] Update 'src/config/config.js' --- src/config/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/config.js b/src/config/config.js index 406357d5..5afb90a0 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -30,7 +30,7 @@ const defaultDatabase = "arminta-tank-db"; async function dbConnection() { try { - db.connect(databaseURLNew); + db.connect(databaseURLNew,{ user: "armintatankdbuser", pass: "armintatank1", useUnifiedTopology: true}); // db.connect(databaseURLNew) db.connection.on("connected", function () { console.log( From 2ebbb543041443280f436e2be42b3f77dd2f5e99 Mon Sep 17 00:00:00 2001 From: varun Date: Tue, 17 Oct 2023 03:09:01 -0400 Subject: [PATCH 06/13] database url changed --- src/config/config.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/config/config.js b/src/config/config.js index 0b1f4ff5..0e890ca5 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -21,7 +21,9 @@ var termination = chalk.bold.magenta; // TODO // Need to read database url from a environment variable. // const databaseURL = "mongodb://armintatankdbuser:armintatank1@35.207.198.4:27017/arminta-tank-db; -const databaseURLNew = "mongodb://35.207.198.4:27017/arminta-tank-db"; +//const databaseURLNew = "mongodb://35.207.198.4:27017/arminta-tank-db"; +const databaseURLNew = "mongodb://35.200.129.165:27017/health-care-db"; + // const databaseURLNew = "mongodb://127.0.0.1:27017/arminta-tank-db"; // Next line not used , or no need to pass default db in the mongo connection url. const defaultDatabase = "arminta-tank-db"; @@ -30,7 +32,9 @@ const defaultDatabase = "arminta-tank-db"; async function dbConnection() { try { - db.connect(databaseURLNew, { user: "armintatankdbuser", pass: "armintatank1" , useUnifiedTopology: true, }); + // db.connect(databaseURLNew, { user: "armintatankdbuser", pass: "armintatank1" , useUnifiedTopology: true, }); + db.connect(databaseURLNew, { user: "healthcaredbuser01", pass: "healthcare01" , useUnifiedTopology: true, }); + // db.connect(databaseURLNew) db.connection.on("connected", function () { console.log( From 39404e6cfba925d3e820ee34638b77f044e6515f Mon Sep 17 00:00:00 2001 From: varun Date: Tue, 17 Oct 2023 06:10:16 -0400 Subject: [PATCH 07/13] write motor status --- src/controllers/tanksController.js | 49 +++++++++++++++++++++- src/routes/tanksRoute.js | 66 +++++++++++++++++++++++++++++- 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 88fb50f6..f3598eb7 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1346,7 +1346,7 @@ exports.totalwaterLevelSum = async (request, reply) => { } ]); - const result = waterlevelSum[0]?totalWaterlevel : 0 + const result = waterlevelSum[0]?.totalWaterlevel ?? 0; reply.send({ waterlevelSum: result }); } @@ -1567,4 +1567,51 @@ exports.motortemperature = async (req, reply) => { catch (err) { throw boom.boomify(err); } +}; + +exports.readMotorStatus = async (req, reply) => { + try { + const { motor_id, action } = req.body; + + // Perform any necessary logic based on action (1: Start, 2: Stop) + + // For example, you can update a database or trigger an action + + const motorInfo = await Tank.findOne({ motor_id: motor_id }); + const motor_stp_status = motorInfo.motor_stop_status + if (motor_stp_status === "1"){ + + } + + reply.send({ status_code: 200, message: `Motor ${motor_id} is set to ${action === '1' ? 'start' : 'stop'}` }); + } catch (err) { + throw boom.boomify(err); + } +}; + +exports.writeMotorStatus = async (req, reply) => { + try { + const { motor_id, status, current, temp } = req.body; + + // Perform any necessary logic to handle motor status update from the device + + // For example, update a database with the new status, current, and temp values + let result; + + if (status === 'on') { + result = await Tank.findOneAndUpdate( + { motor_id: motor_id }, + { $set: { motor_status: "2" } } + ); + } else if (status === 'off') { + result = await Tank.findOneAndUpdate( + { motor_id: motor_id }, + { $set: { motor_stop_status: "1" } } + ); + } + + reply.send({ status_code: 200, message: `Motor ${motor_id} status updated to ${status}` }); + } catch (err) { + throw boom.boomify(err); + } }; \ No newline at end of file diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 74908da0..42aeaf51 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -686,7 +686,71 @@ module.exports = function (fastify, opts, next) { }); - + 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'], + // }, + // // 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 + // }); + + next(); } From 86c405571aa03b732ce0a8f162bb7adf8f596de6 Mon Sep 17 00:00:00 2001 From: gitadmin Date: Tue, 17 Oct 2023 10:23:29 +0000 Subject: [PATCH 08/13] Update 'src/controllers/tanksController.js' --- src/controllers/tanksController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index f3598eb7..0526300d 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1346,7 +1346,7 @@ exports.totalwaterLevelSum = async (request, reply) => { } ]); - const result = waterlevelSum[0]?.totalWaterlevel ?? 0; + const result = waterlevelSum[0]?totalWaterlevel : 0; reply.send({ waterlevelSum: result }); } From 378e2c45c6543454db71f88f47ecae816931a8af Mon Sep 17 00:00:00 2001 From: varun Date: Thu, 19 Oct 2023 00:59:07 -0400 Subject: [PATCH 09/13] read write and get motor status --- src/controllers/tanksController.js | 130 ++++++----------------- src/routes/tanksRoute.js | 165 +++++------------------------ 2 files changed, 56 insertions(+), 239 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index f3598eb7..9cf0cb37 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1445,56 +1445,11 @@ exports.deletemotordatarecordsbefore7days = async (req, reply) => { -exports.startmotoriot = async (req, reply) => { - - try { - var motor_id = req.body.motor_id; - - - - - const result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_status: "2" } } - ); - //return update; - console.log(result) - reply.send({ status_code: 200}); - - - - } - catch (err) { - throw boom.boomify(err); - } -}; - - -exports.stopmotoriot = async (req, reply) => { - - try { - var motor_id = req.body.motor_id; - - - - - const result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_status: "1" } } - ); - //return update; - console.log(result) - reply.send({ status_code: 200}); - } - catch (err) { - throw boom.boomify(err); - } -}; @@ -1521,69 +1476,20 @@ exports.motorstatus = async (req, reply) => { } }; -exports.motorspeed = async (req, reply) => { - - try { - const motor_id = req.body.motor_id; - const speed = req.body.speed; - - - - - const result = await Tank.findOneAndUpdate( - { motor_id: motor_id }, - { $set: { motor_speed: speed } } - ); - //return update; - console.log(result) - reply.send({ status_code: 200}); - - - - } - catch (err) { - throw boom.boomify(err); - } -}; - -exports.motortemperature = async (req, reply) => { - - try { - const motor_id = req.params.motor_id; - console.log(motor_id) - - const motorInfo = await Tank.findOne({ motor_id: motor_id }); - - console.log(motorInfo) - - - //return update; - - reply.send({ status_code: 200,temperature:motorInfo.motor_temperfature}); - - - - } - catch (err) { - throw boom.boomify(err); - } -}; exports.readMotorStatus = async (req, reply) => { try { - const { motor_id, action } = req.body; + const motor_id = req.query.motor_id; // Perform any necessary logic based on action (1: Start, 2: Stop) // For example, you can update a database or trigger an action const motorInfo = await Tank.findOne({ motor_id: motor_id }); - const motor_stp_status = motorInfo.motor_stop_status - if (motor_stp_status === "1"){ + const motor_stp_status = motorInfo.motor_status - } - reply.send({ status_code: 200, message: `Motor ${motor_id} is set to ${action === '1' ? 'start' : 'stop'}` }); + reply.send({ status_code: 200, motor_status:motor_stp_status }); } catch (err) { throw boom.boomify(err); } @@ -1614,4 +1520,32 @@ exports.writeMotorStatus = async (req, reply) => { } catch (err) { throw boom.boomify(err); } -}; \ No newline at end of file +}; + +exports.changeMotorStatus = async (req, reply) => { + try { + const motor_id = req.body.motor_id; + const action =req.body.action + + // Perform any necessary logic to handle motor status update from the device + + // For example, update a database with the new status, current, and temp values + + + + const result = await Tank.findOneAndUpdate( + { motor_id: motor_id }, + { $set: { motor_status: action } }); + + + + reply.send({ status_code: 200}); + } catch (err) { + throw boom.boomify(err); + } +}; + + + + + diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 42aeaf51..3d9a2584 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -573,184 +573,67 @@ module.exports = function (fastify, opts, next) { - fastify.route({ - method: 'PUT', - url: '/api/motors/start', - + fastify.post('/api/motor/write', { schema: { tags: ["Tank"], - description: "This is to start motor using IOT", - summary: "This is to start motor using IOT", + 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' }, }, - required: ["motor_id"] }, - + }, - handler: tanksController.startmotoriot + handler: tanksController.writeMotorStatus + }); - fastify.route({ - method: 'PUT', - url: '/api/motors/stop', - + fastify.get('/api/motor/read', { schema: { tags: ["Tank"], - description: "This is to stop motor using IOT", - summary: "This is to stop motor using IOT", - body: { + 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"] + // required: ['motor_id'], }, - + }, - handler: tanksController.stopmotoriot + handler: tanksController.readMotorStatus }); - fastify.route({ - method: 'GET', - url: '/api/motors/status/:motor_id', - - schema: { - tags: ["Tank"], - description: "This is to get motor status", - summary: "This is to get motor status", - params: { - required: ["motor_id"], - type: "object", - properties: { - motor_id: { - type: "string", - description: "motor_id", - }, - }, - }, - - }, - handler: tanksController.motorstatus - }); - - fastify.route({ - method: 'PUT', - url: '/api/motors/speed', - + fastify.post('/api/motor/changeMotorStatus', { schema: { tags: ["Tank"], - description: "This is to change motor pumping speed using IOT", - summary: "This is to to change motor pumping speed using IOT", + description: "This is to change the motor status", + summary: "This is to change the motor status", + body: { type: 'object', properties: { motor_id: { type: 'string' }, - speed: { type: 'string' }, + action: { type: 'string' }, }, required: ["motor_id"] }, }, - handler: tanksController.motorspeed + handler: tanksController.changeMotorStatus }); - fastify.route({ - method: 'GET', - url: '/api/motors/temperature/:motor_id', - - schema: { - tags: ["Tank"], - description: "This is to get motor temperature", - summary: "This is to get motor temperature", - params: { - required: ["motor_id"], - type: "object", - properties: { - motor_id: { - type: "string", - description: "motor_id", - }, - }, - }, - - }, - handler: tanksController.motortemperature - }); - - - 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'], - // }, - // // 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 - // }); - - next(); } From 882402965d55f25639edbf55ea45fb9210753ad5 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 1 Dec 2023 00:55:55 -0500 Subject: [PATCH 10/13] changes in verify user --- src/routes/usersRoute.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes/usersRoute.js b/src/routes/usersRoute.js index 27ee224f..70f7b944 100644 --- a/src/routes/usersRoute.js +++ b/src/routes/usersRoute.js @@ -168,7 +168,7 @@ module.exports = function (fastify, opts, next) { }, preHandler: [ validationHandler.fieldCheck, - validationHandler.verifyUser, + // validationHandler.verifyUser, // validationHandler.validatePhoneFormat, validationHandler.validateEmailFormat, ], From ee8bd5a4261d7a616f09fc83604a68a63fa3d340 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 1 Dec 2023 01:05:44 -0500 Subject: [PATCH 11/13] changes in verify user --- src/config/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/config.js b/src/config/config.js index 0e890ca5..5afdd88a 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -30,6 +30,7 @@ const defaultDatabase = "arminta-tank-db"; //export this function and imported by server.js + async function dbConnection() { try { // db.connect(databaseURLNew, { user: "armintatankdbuser", pass: "armintatank1" , useUnifiedTopology: true, }); From 48e331d3a67127f16b64139c0ffcf54bfe0a9c32 Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 1 Dec 2023 01:27:02 -0500 Subject: [PATCH 12/13] changes in read motor status --- src/controllers/tanksController.js | 4 ++-- src/models/tanks.js | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 2ded7afa..a161f5bc 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1486,10 +1486,10 @@ exports.readMotorStatus = async (req, reply) => { // For example, you can update a database or trigger an action const motorInfo = await Tank.findOne({ motor_id: motor_id }); - const motor_stp_status = motorInfo.motor_status + const motor_status = motorInfo.motor_status - reply.send({ status_code: 200, motor_status:motor_stp_status }); + reply.send({ status_code: 200, motor_status:motor_status }); } catch (err) { throw boom.boomify(err); } diff --git a/src/models/tanks.js b/src/models/tanks.js index 66750896..637134a8 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -71,6 +71,7 @@ const tanksSchema = new mongoose.Schema({ } }); + const motordataSchema = new mongoose.Schema({ From 95b77c9891559fdaa6656c8d5e0d9ba6a683ff6d Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 1 Dec 2023 01:35:44 -0500 Subject: [PATCH 13/13] user handler password error --- src/handlers/userHandler.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/handlers/userHandler.js b/src/handlers/userHandler.js index 97e82db7..ae23d3c2 100644 --- a/src/handlers/userHandler.js +++ b/src/handlers/userHandler.js @@ -129,6 +129,8 @@ exports.verifyUser = async (req, reply) => { throw boom.boomify(err); } }; + + exports.validatePhoneFormat = async (req, reply) => { try { var user = new User(req.body); @@ -360,6 +362,7 @@ exports.verifyPhone = async (req, reply) => { throw boom.boomify(err); } }; + exports.sendPhoneVerificationCode = async (req, reply) => { // Setting a regError in request so a user is not sent a verificaiton code if registration is not successful // checkign if regError property is available in the req body, if it exists , do not send the message @@ -545,7 +548,7 @@ exports.sendPasswordResetCode = async (req) => { // var authToken = twilioAuthToken; // Your Auth Token from www.twilio.com/console var client = new twilio(twilioAccountSid, twilioAuthToken); // var code = Math.floor(100000 + Math.random() * 900000); - code = user.passwordResetCode.toString(); + //code = user.passwordResetCode.toString(); // Message format to allow app to autopickup sms message and // verify the code.