|
|
|
@ -350,34 +350,40 @@ exports.getTanksofParticularInstaller = async (req, reply) => {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//};
|
|
|
|
//};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTankmotordata = async (req, reply) => {
|
|
|
|
exports.getTankmotordata = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const { startDate, stopDate, block } = req.body;
|
|
|
|
const { startDate, stopDate } = req.body;
|
|
|
|
const { customerId } = req.params;
|
|
|
|
const { customerId } = req.params;
|
|
|
|
const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
|
|
|
const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
// Parse the input startDate and stopDate using the desired format
|
|
|
|
|
|
|
|
// const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
|
|
|
// const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
|
|
|
// console.log(start,"start",end,"end")
|
|
|
|
|
|
|
|
// Check if the parsed dates are valid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convert the dates to the correct format for storage or querying (still in UTC)
|
|
|
|
|
|
|
|
// This gives a native JS Date object for querying
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch the name from the User collection based on customerId, only from profile
|
|
|
|
// Fetch the name from the User collection based on customerId, only from profile
|
|
|
|
const user = await User.findOne({ customerId })
|
|
|
|
const user = await User.findOne({ customerId })
|
|
|
|
.select("profile.firstName profile.lastName");
|
|
|
|
.select("username");
|
|
|
|
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
if (user) {
|
|
|
|
// Get the full name (combine firstName and lastName if available)
|
|
|
|
// Get the full name (combine firstName and lastName if available)
|
|
|
|
const userName = user.profile.firstName && user.profile.lastName
|
|
|
|
const userName = user.username
|
|
|
|
? `${user.profile.firstName} ${user.profile.lastName}`
|
|
|
|
? `${user.username}`
|
|
|
|
: "N/A"; // Fallback if no name is found
|
|
|
|
: "N/A"; // Fallback if no name is found
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the query object for motor data based on customerId
|
|
|
|
// Construct the query object for motor data based on customerId
|
|
|
|
const motorQuery = { customerId };
|
|
|
|
const motorQuery = { customerId };
|
|
|
|
|
|
|
|
|
|
|
|
// If block is provided (and not "All"), add it to the query
|
|
|
|
|
|
|
|
if (block !== "All") motorQuery.block = block;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch motor data for the customerId within the time range
|
|
|
|
// Fetch motor data for the customerId within the time range
|
|
|
|
const motorDataDocs = await MotorData.find(motorQuery)
|
|
|
|
const motorDataDocs = await MotorData.find(motorQuery)
|
|
|
|
.where("date")
|
|
|
|
.where("startTime")
|
|
|
|
.gte(start) // Greater than or equal to startDate
|
|
|
|
.gte(startDate) // Greater than or equal to startDate
|
|
|
|
.lte(end) // Less than or equal to stopDate
|
|
|
|
.lte(stopDate) // Less than or equal to stopDate
|
|
|
|
.exec();
|
|
|
|
.exec();
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
reply.send({
|
|
|
|
@ -396,6 +402,10 @@ exports.getTankmotordata = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateTanklevels = async (req, reply) => {
|
|
|
|
exports.updateTanklevels = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|