From 4fc7443fa1425751ade38b4e0657534a1469c29e Mon Sep 17 00:00:00 2001 From: Bhaskara Kishore Date: Fri, 14 Apr 2023 11:37:10 +0530 Subject: [PATCH] add timestmap and hardwareId --- src/controllers/tanksController.js | 10 ++++++++-- src/models/tanks.js | 3 +++ src/routes/tanksRoute.js | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index fa2b0fb6..f27b95cc 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -8,6 +8,7 @@ const fastify = require("fastify")({ }); // const tanksController = require("./tanksController") +const moment = require('moment'); exports.addTanks = async (req, reply) => { @@ -27,6 +28,7 @@ console.log(req.params); // console.log("This is the reply in the handler after the validations", reply); tankData = { customerId: customerId, + hardwareId: req.body.hardwareId, tankName: req.body.tankName, blockName: req.body.blockName, capacity: req.body.capacity, @@ -52,6 +54,7 @@ console.log(req.params); usertobeInserted = checkFormEncoding.tank; console.log("thsi true url string"); tank.customerId = usertobeInserted.customerId + tank.hardwareId = usertobeInserted.hardwareId; tank.tankName = usertobeInserted.tankName; tank.blockName = usertobeInserted.blockName; tank.capacity = usertobeInserted.capacity; @@ -661,10 +664,13 @@ if(shape==="horizontalellipse"){ exports.IotDevice = async (req, reply) => { try { - const { hardwareId, tankHeight, maxLevel, minLevel, mode } = req.body; + const { hardwareId, tankHeight, maxLevel, minLevel, mode } = req.body; + // create a new tank document with timestamp + const timestamp = moment().format('DD-MM-YY hh:mm:ss'); + const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode, timestamp }); // create a new tank document - const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode }); + // const tank = new IotData({ hardwareId, tankHeight, maxLevel, minLevel, mode }); // save the document to MongoDB await tank.save(); diff --git a/src/models/tanks.js b/src/models/tanks.js index 508f688d..8d38dba8 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -1,4 +1,5 @@ const mongoose = require("mongoose"); +const moment = require('moment'); @@ -9,6 +10,7 @@ const ObjectId = Schema.Types.ObjectId; const code = Math.floor(100000 + Math.random() * 900000); const RoleSchema = new Schema({ name: String }); const tanksSchema = new mongoose.Schema({ + hardwareId: { type: String, unique: true, required: true }, customerId: { type: String, default: null }, tankName: { type: String, default: null }, blockName: { type: String, default: null }, @@ -46,6 +48,7 @@ const IOttankSchema = new mongoose.Schema({ tankHeight: { type: String, required: true }, maxLevel: { type: String, required: true }, minLevel: { type: String, required: true }, + timestamp: { type: String, default: moment().format('DD-MM-YY hh:mm:ss') }, mode: { type: Number, required: true } }); diff --git a/src/routes/tanksRoute.js b/src/routes/tanksRoute.js index 1dedcbd3..642781c7 100644 --- a/src/routes/tanksRoute.js +++ b/src/routes/tanksRoute.js @@ -23,6 +23,7 @@ module.exports = function (fastify, opts, next) { body: { type: "object", properties: { + hardwareId: { type: "string" }, tankName: { type: "string" }, blockName: { type: "string"}, capacity: { type: "string" },