diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index d48fbe7e..ee7677ef 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1228,27 +1228,22 @@ exports.consumption = async (request, reply) => { ).toFixed(2); // Include the total consumption in the response - const response = { - status_code: 200, - tankData, - consumptiorecordsdatewise: tankconsumptionData, - totalConsumptionPercentage, - ...(typeofwater === "all" - ? { - totalConsumptionPercentageForBore: boreConsumptionPercentage, - totalConsumptionPercentageForDrinking: drinkingConsumptionPercentage, - totalConsumptionForBore: totalBoreConsumptionForSelectedBlockAndTypeOfWater, - totalConsumptionForDrinking: totalDrinkingConsumptionForSelectedBlockAndTypeOfWater, - } - : { - [`total consumption of ${typeofwater} and selected block`]: - typeofwater === "bore" - ? totalBoreConsumptionForSelectedBlockAndTypeOfWater - : totalDrinkingConsumptionForSelectedBlockAndTypeOfWater, - } - ), - [`total consumption of ${typeofwater} and selected block`]: totalConsumptionForSelectedBlockAndTypeOfWater - }; + // Construct the response +const response = { + status_code: 200, + tankData, + consumptiorecordsdatewise: tankconsumptionData, + totalConsumptionPercentage, + totalConsumptionPercentageForBore: typeofwater !== "drinking" ? boreConsumptionPercentage : 0, + totalConsumptionPercentageForDrinking: typeofwater !== "bore" ? drinkingConsumptionPercentage : 0, + totalConsumptionForBore: typeofwater !== "drinking" ? totalBoreConsumptionForSelectedBlockAndTypeOfWater : 0, + totalConsumptionForDrinking: typeofwater !== "bore" ? totalDrinkingConsumptionForSelectedBlockAndTypeOfWater : 0, + [`total consumption of ${typeofwater} and selected block`]: totalConsumptionForSelectedBlockAndTypeOfWater +}; + +// Send the response + + reply.send(response); } catch (err) {