changes in motordata

master^2
Varun 9 months ago
parent 9f03a62bf1
commit 71227be09a

@ -394,36 +394,45 @@ 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({
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 // Query the MotorData collection
const motorDataDocs = await MotorData.find({ // const motorDataDocs = await MotorData.find({
customerId, // customerId,
$or: [ // $or: [
{ // {
startTime: { $gte: startISODate, $lte: stopISODate }, // Date-based comparison // startTime: { $gte: startISODate, $lte: stopISODate }, // Date-based comparison
}, // },
{ // {
startTime: { $gte: startStringDate, $lte: stopStringDate }, // String-based comparison // startTime: { $gte: startStringDate, $lte: stopStringDate }, // String-based comparison
}, // },
], // ],
}).exec(); // }).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