ashok 9 months ago
commit 093fcd8b36

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

Loading…
Cancel
Save