add timestmap and hardwareId

master
Bhaskara Kishore 3 years ago
parent b52fc1067b
commit 4fc7443fa1

@ -8,6 +8,7 @@ const fastify = require("fastify")({
}); });
// const tanksController = require("./tanksController") // const tanksController = require("./tanksController")
const moment = require('moment');
exports.addTanks = async (req, reply) => { 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); // console.log("This is the reply in the handler after the validations", reply);
tankData = { tankData = {
customerId: customerId, customerId: customerId,
hardwareId: req.body.hardwareId,
tankName: req.body.tankName, tankName: req.body.tankName,
blockName: req.body.blockName, blockName: req.body.blockName,
capacity: req.body.capacity, capacity: req.body.capacity,
@ -52,6 +54,7 @@ console.log(req.params);
usertobeInserted = checkFormEncoding.tank; usertobeInserted = checkFormEncoding.tank;
console.log("thsi true url string"); console.log("thsi true url string");
tank.customerId = usertobeInserted.customerId tank.customerId = usertobeInserted.customerId
tank.hardwareId = usertobeInserted.hardwareId;
tank.tankName = usertobeInserted.tankName; tank.tankName = usertobeInserted.tankName;
tank.blockName = usertobeInserted.blockName; tank.blockName = usertobeInserted.blockName;
tank.capacity = usertobeInserted.capacity; tank.capacity = usertobeInserted.capacity;
@ -661,10 +664,13 @@ if(shape==="horizontalellipse"){
exports.IotDevice = async (req, reply) => { exports.IotDevice = async (req, reply) => {
try { 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 // 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 // save the document to MongoDB
await tank.save(); await tank.save();

@ -1,4 +1,5 @@
const mongoose = require("mongoose"); 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 code = Math.floor(100000 + Math.random() * 900000);
const RoleSchema = new Schema({ name: String }); const RoleSchema = new Schema({ name: String });
const tanksSchema = new mongoose.Schema({ const tanksSchema = new mongoose.Schema({
hardwareId: { type: String, unique: true, required: true },
customerId: { type: String, default: null }, customerId: { type: String, default: null },
tankName: { type: String, default: null }, tankName: { type: String, default: null },
blockName: { type: String, default: null }, blockName: { type: String, default: null },
@ -46,6 +48,7 @@ const IOttankSchema = new mongoose.Schema({
tankHeight: { type: String, required: true }, tankHeight: { type: String, required: true },
maxLevel: { type: String, required: true }, maxLevel: { type: String, required: true },
minLevel: { 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 } mode: { type: Number, required: true }
}); });

@ -23,6 +23,7 @@ module.exports = function (fastify, opts, next) {
body: { body: {
type: "object", type: "object",
properties: { properties: {
hardwareId: { type: "string" },
tankName: { type: "string" }, tankName: { type: "string" },
blockName: { type: "string"}, blockName: { type: "string"},
capacity: { type: "string" }, capacity: { type: "string" },

Loading…
Cancel
Save