|
|
|
@ -105,7 +105,7 @@ exports.addTanks = async (req, reply) => {
|
|
|
|
|
if (existingTank) {
|
|
|
|
|
throw new Error('The combination of hardwareId and tankhardwareId already exists.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tankData = {
|
|
|
|
|
// InstallerId:InstallerId,
|
|
|
|
|
customerId: customerId,
|
|
|
|
@ -222,6 +222,64 @@ exports.getTank = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanksensorcount = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { customerId } = req.params;
|
|
|
|
|
|
|
|
|
|
// Aggregate to count need_sensor values
|
|
|
|
|
const needSensorCounts = await Tank.aggregate([
|
|
|
|
|
{ $match: { customerId } },
|
|
|
|
|
{
|
|
|
|
|
$group: {
|
|
|
|
|
_id: "$need_sensor",
|
|
|
|
|
count: { $sum: 1 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const inputIsMotorCounts = await Tank.aggregate([
|
|
|
|
|
{ $match: { customerId } },
|
|
|
|
|
{ $unwind: "$connections.inputConnections" },
|
|
|
|
|
{
|
|
|
|
|
$group: {
|
|
|
|
|
_id: "$connections.inputConnections.inputismotor",
|
|
|
|
|
count: { $sum: 1 },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Format the results
|
|
|
|
|
const needSensorResult = needSensorCounts.reduce((acc, item) => {
|
|
|
|
|
acc[item._id] = item.count;
|
|
|
|
|
return acc;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
const inputIsMotorResult = inputIsMotorCounts.reduce((acc, item) => {
|
|
|
|
|
acc[item._id ? "true" : "false"] = item.count;
|
|
|
|
|
return acc;
|
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
|
|
// Return the response
|
|
|
|
|
reply.send({
|
|
|
|
|
customerId,
|
|
|
|
|
needSensor: {
|
|
|
|
|
yes: needSensorResult["yes"] || 0,
|
|
|
|
|
no: needSensorResult["no"] || 0,
|
|
|
|
|
},
|
|
|
|
|
inputIsMotor: {
|
|
|
|
|
true: inputIsMotorResult["true"] || 0,
|
|
|
|
|
false: inputIsMotorResult["false"] || 0,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reply.status(500).send({ error: "An error occurred while fetching the data." });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getTanksofParticularInstaller = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
await Tank.find({InstallerId: req.query.InstallerId})
|
|
|
|
@ -3820,6 +3878,28 @@ exports.getLatestData = async (req, reply) => {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
exports.changesurveystatus = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const customerId = req.params.customerId;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await User.findOneAndUpdate(
|
|
|
|
|
{ customerId: customerId },
|
|
|
|
|
{ $set: { survey_status: req.body.survey_status } },
|
|
|
|
|
{ new: true }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.code(200).send({ result });
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
// send an error response
|
|
|
|
|
reply.code(500).send({ error: err.message });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.checkStatusofIot = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
@ -4630,6 +4710,33 @@ client.on('message', async (topic, message) => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getPendingAndCompletedsurveyOfparticularInstaller = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { installationId } = request.params;
|
|
|
|
|
const survey_status = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const surveydata = await User.find({
|
|
|
|
|
installationId,
|
|
|
|
|
survey_status,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Send the response, including both total consumption and filtered consumption records
|
|
|
|
|
reply.send({
|
|
|
|
|
status_code: 200,
|
|
|
|
|
surveydata,
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
throw boom.boomify(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.consumptionofparticulartank = async (request, reply) => {
|
|
|
|
|
try {
|
|
|
|
|