calculate the sum of type of water level

master
Bhaskara Kishore 2 years ago
parent 0c775a5de1
commit 50f22797d8

@ -199,22 +199,33 @@ exports.getTanklevels = async (req, reply) => {
try { try {
const customerId = req.params.customerId; const customerId = req.params.customerId;
const updated_data = await Tank.find({ customerId: customerId }); const updated_data = await Tank.find({ customerId: customerId });
reply.send({ status_code: 200, data: updated_data});
let sumSumpDrinkingWater = 0;
let sumOverheadDrinkingWater = 0;
return { message: 'success' }; updated_data.forEach((tank) => {
} if (tank.tankLocation === 'sump' && tank.typeOfWater === 'Drinking Water') {
sumSumpDrinkingWater += parseInt(tank.waterlevel);
} else if (tank.tankLocation === 'overhead' && tank.typeOfWater === 'Drinking Water') {
sumOverheadDrinkingWater += parseInt(tank.waterlevel);
}
});
catch (err) { reply.send({
status_code: 200,
data: updated_data,
totalDrinkingWaterInSump: sumSumpDrinkingWater,
totalDrinkingWaterInOverhead: sumOverheadDrinkingWater
});
return { message: 'success' };
} catch (err) {
throw boom.boomify(err); throw boom.boomify(err);
} }
}; };
exports.motorAction = async (req, reply) => { exports.motorAction = async (req, reply) => {
try { try {
//let start_time,stop_time //let start_time,stop_time

@ -31,30 +31,32 @@ module.exports = function (fastify, opts, next) {
tankerName: { type: "string" }, tankerName: { type: "string" },
phoneNumber: { type: "string"}, phoneNumber: { type: "string"},
alternative_phoneNumber: { type: "string"}, alternative_phoneNumber: { type: "string"},
typeofwater: { // typeofwater: {
type: "array", // type: "array",
maxItems: 2500, // maxItems: 2500,
items: { // items: {
type: "object", // type: "object",
properties: { // properties: {
typeofwater: { type: "string", default: null }, // typeofwater: { type: "string", default: null },
}, // },
}, // },
}, // },
price: { // price: {
type: "array", // type: "array",
maxItems: 2500, // maxItems: 2500,
items: { // items: {
type: "object", // type: "object",
properties: { // properties: {
price: { type: "string", default: null }, // price: { type: "string", default: null },
}, // },
}, // },
}, // },
typeofwater: { type: "string"},
price: { type: "string"},
capacity: { type: "string"}, capacity: { type: "string"},
// price: {type : "string"}, // price: {type : "string"},
// status: {type: "string"} // status: {type: "string"}
@ -104,27 +106,29 @@ module.exports = function (fastify, opts, next) {
tankerName: { type: "string" }, tankerName: { type: "string" },
phoneNumber: { type: "string"}, phoneNumber: { type: "string"},
alternative_phoneNumber: { type: "string"}, alternative_phoneNumber: { type: "string"},
typeofwater: { // typeofwater: {
type: "array", // type: "array",
maxItems: 2500, // maxItems: 2500,
items: { // items: {
type: "object", // type: "object",
properties: { // properties: {
typeofwater: { type: "string", default: null }, // typeofwater: { type: "string", default: null },
}, // },
}, // },
}, // },
price: { // price: {
type: "array", // type: "array",
maxItems: 2500, // maxItems: 2500,
items: { // items: {
type: "object", // type: "object",
properties: { // properties: {
price: { type: "string", default: null }, // price: { type: "string", default: null },
}, // },
}, // },
}, // },
typeofwater: { type: "string"},
price: { type: "string"},
capacity: { type: "string"}, capacity: { type: "string"},

Loading…
Cancel
Save