|
|
|
@ -394,36 +394,45 @@ exports.getTankmotordata = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert input dates to ISO 8601 format for Date comparison
|
|
|
|
|
const startISODate = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
const stopISODate = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Convert input dates to string format for string-based comparison
|
|
|
|
|
const startStringDate = moment(startDate, "DD-MMM-YYYY - HH:mm").format("DD-MMM-YYYY - HH:mm");
|
|
|
|
|
const stopStringDate = moment(stopDate, "DD-MMM-YYYY - HH:mm").format("DD-MMM-YYYY - HH:mm");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch the username based on customerId
|
|
|
|
|
const user = await User.findOne({ customerId }).select("username");
|
|
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
|
const userName = user.username || "N/A";
|
|
|
|
|
const motordatas = await MotorData.find({
|
|
|
|
|
customerId,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const filtereddatas = motordatas.filter((record) => {
|
|
|
|
|
const recordTime = moment(record.startTime, "DD-MMM-YYYY - HH:mm").toDate();
|
|
|
|
|
return recordTime >= start && recordTime <= end;
|
|
|
|
|
});
|
|
|
|
|
// Query the MotorData collection
|
|
|
|
|
const motorDataDocs = await MotorData.find({
|
|
|
|
|
customerId,
|
|
|
|
|
$or: [
|
|
|
|
|
{
|
|
|
|
|
startTime: { $gte: startISODate, $lte: stopISODate }, // Date-based comparison
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
startTime: { $gte: startStringDate, $lte: stopStringDate }, // String-based comparison
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}).exec();
|
|
|
|
|
// const motorDataDocs = await MotorData.find({
|
|
|
|
|
// customerId,
|
|
|
|
|
// $or: [
|
|
|
|
|
// {
|
|
|
|
|
// startTime: { $gte: startISODate, $lte: stopISODate }, // Date-based comparison
|
|
|
|
|
// },
|
|
|
|
|
// {
|
|
|
|
|
// startTime: { $gte: startStringDate, $lte: stopStringDate }, // String-based comparison
|
|
|
|
|
// },
|
|
|
|
|
// ],
|
|
|
|
|
// }).exec();
|
|
|
|
|
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
data: motorDataDocs,
|
|
|
|
|
count: motorDataDocs.length,
|
|
|
|
|
data: filtereddatas,
|
|
|
|
|
count: filtereddatas.length,
|
|
|
|
|
customerName: userName,
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|