diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index 328773de..9e480ca8 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1,5 +1,5 @@ //const Tank = require("../models/tanks"); -const { Tank, MotorData, IotData,MotorIot,TankWaterLevel,TankConsumptionSchema } = require('../models/tanks') +const { Tank, MotorData, IotData,MotorIot,TankWaterLevel,TankConsumptionSchema,TankConsumptionOriginalSchema } = require('../models/tanks') const {User} = require("../models/User"); const boom = require("boom"); @@ -940,7 +940,7 @@ let supplier_tanks = []; exports.consumption = async (request, reply) => { - try {SS + try { const { customerId } = request.params; const { startDate, stopDate, block, typeofwater } = request.body; @@ -2370,7 +2370,7 @@ const updatetotalConsumptiontillmidnight = async () => { const formattedDate = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); // Check if the record already exists - const existingRecord = await TankConsumptionSchema.findOne({ + const existingRecord = await TankConsumptionOriginalSchema.findOne({ customerId: tank.customerId, tankName: tank.tankName, tankLocation: tank.tankLocation, @@ -2379,7 +2379,7 @@ const updatetotalConsumptiontillmidnight = async () => { if (!existingRecord) { // Create and save the new document if it doesn't exist - const newTankConsumption = new TankConsumptionSchema({ + const newTankConsumption = new TankConsumptionOriginalSchema({ customerId: tank.customerId, tankName: tank.tankName, tankLocation: tank.tankLocation, @@ -2428,7 +2428,7 @@ console.log('Scheduled task to update total consumption till midnight.'); // // Format the date in the desired format // const formattedDate = moment().tz('Asia/Kolkata').format('DD-MMM-YYYY - HH:mm'); -// const newTankConsumption = new TankConsumptionSchema({ +// const newTankConsumption = new TankConsumptionOriginalSchema({ // customerId: tank.customerId, // tankName: tank.tankName, // tankLocation: tank.tankLocation, diff --git a/src/models/tanks.js b/src/models/tanks.js index 57105b05..487eec58 100644 --- a/src/models/tanks.js +++ b/src/models/tanks.js @@ -151,6 +151,16 @@ const tankconsumptionSchema = new mongoose.Schema({ time: { type: String } }); + +const tankconsumptionoriginalSchema = new mongoose.Schema({ + customerId: { type: String }, + tankName: { type: String }, + tankLocation: { type: String }, + consumption: { type: String }, + block:{type: String}, + typeofwater:{type:String}, + time: { type: String } +}); const Tank = mongoose.model("Tank", tanksSchema); @@ -158,8 +168,10 @@ const MotorData = mongoose.model("MotorData", motordataSchema); const TankWaterLevel = mongoose.model("TankWaterLevel", tankWaterLevelSchema); const IotData = mongoose.model("IotData", IOttankSchema); const TankConsumptionSchema = mongoose.model("TankConsumptionSchema", tankconsumptionSchema); +const TankConsumptionOriginalSchema = mongoose.model("TankConsumptionOriginalSchema", tankconsumptionoriginalSchema); + module.exports = { - Tank, MotorData,IotData,TankWaterLevel,TankConsumptionSchema + Tank, MotorData,IotData,TankWaterLevel,TankConsumptionSchema,TankConsumptionOriginalSchema }