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 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();

@ -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 }
});

@ -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" },

Loading…
Cancel
Save