added total sensor count in get tanks

master
Varun 9 months ago
parent 4903e2a4a8
commit 684dbcadec

@ -211,8 +211,8 @@ exports.getTank = async (req, reply) => {
await Tank.find({ customerId: req.query.customerId })
.exec()
.then((docs) => {
// Transform the response to include switch_count and calculate totalSwitchCount
let totalSwitchCount = 0;
let totalSensorCount = 0;
const transformedDocs = docs.map((tank) => {
const inputConnections = tank.connections?.inputConnections || [];
@ -222,6 +222,11 @@ exports.getTank = async (req, reply) => {
totalSwitchCount += switchCount; // Accumulate the switch_count
// Check if the tank has need_sensor set to "yes"
if (tank.need_sensor?.toLowerCase() === "yes") {
totalSensorCount++;
}
// Add the switch_count field inside connections
return {
...tank.toObject(), // Convert Mongoose document to plain object
@ -237,6 +242,7 @@ exports.getTank = async (req, reply) => {
data: transformedDocs,
count: transformedDocs.length,
total_switch_count: totalSwitchCount, // Add the total switch count
total_sensor_count: totalSensorCount, // Add the total sensor count
});
})
.catch((err) => {

Loading…
Cancel
Save