From a1be104b6168686ebdd64e7a3ac21e2aac6c16fa Mon Sep 17 00:00:00 2001 From: varun Date: Fri, 10 Mar 2023 02:13:33 -0500 Subject: [PATCH] created schema for start and stop in tanks.js and made changes start and stop to store data --- src/controllers/tanksController.js | 33 +++++++++++++++++++++++++++++- src/models/tanks.js | 20 +++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 3dfbcdaa..be2a3b3d 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1,4 +1,6 @@ -const Tank = require("../models/tanks"); +//const Tank = require("../models/tanks"); +const { Tank, MotorData } = require('../models/tanks') + const User = require("../models/User"); const boom = require("boom"); const fastify = require("fastify")({ @@ -326,6 +328,35 @@ exports.motorAction = async (req, reply) => { }, 2000); } + console.log(customerId,req.body.from,req.body.from_type,receiver_tank,req.body.to_type,) + motorData = { + + customerId:customerId, + supplierTank : req.body.from, + supplier_type: req.body.from_type, + receiverTank: receiver_tank, + receiver_type: req.body.to_type, + + + + }; + var motorData = new MotorData(motorData); + + checkFormEncoding = isUserFormUrlEncoded(req); + if (checkFormEncoding.isUserFormUrlEncoded) { + usertobeInserted = checkFormEncoding.motorData; + console.log("thsi true url string"); + motorData.customerId = customerId; + motorData.supplierTank = req.body.from; + motorData.receiverTank = receiver_tank; + motorData.supplier_type = req.body.from_type; + motorData.receiver_type = req.body.to_type; + + + } + const motor_data = await motorData.save(); + reply.send({ status_code: 200, data: motor_data }); + return motor_data diff --git a/src/models/tanks.js b/src/models/tanks.js index 93065055..6e70f6df 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -24,4 +24,22 @@ const tanksSchema = new mongoose.Schema({ }); -module.exports = mongoose.model("Tank", tanksSchema); \ No newline at end of file + +const motordataSchema = new mongoose.Schema({ + customerId: { type: String, default: null }, + supplierTank: { type: String, default: null }, + receiverTank: { type: String, default: null }, + date: { type: String, default: null }, + time: { type: String, default: null }, + supplier_type: { type: String, default: null }, + receiver_type: { type: String, default: null }, + + +}); + +const Tank = mongoose.model("Tank", tanksSchema); +const MotorData = mongoose.model("MotorData", motordataSchema); + +module.exports = { + Tank, MotorData +}