|
|
@ -657,3 +657,109 @@ exports.addStore = async (request, reply) => {
|
|
|
|
reply.code(500).send(err);
|
|
|
|
reply.code(500).send(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.qccheckwaterlevelSensorSlave = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { storeId } = request.params;
|
|
|
|
|
|
|
|
const updateData = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the document by storeId and tankhardwareId, and update the corresponding slave
|
|
|
|
|
|
|
|
const updatedSensor = await WaterLeverSensor.findOneAndUpdate(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
storeId: storeId,
|
|
|
|
|
|
|
|
"slaves.tankhardware.tankhardwareId": request.body.tankhardwareId
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$set: {
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.qccheck": updateData.qccheck,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.qccheckdate": updateData.qccheckdate,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.qcby": updateData.qcby,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.comment": updateData.comment,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.outforrepairdate": updateData.outforrepairdate,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.sendto": updateData.sendto,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.repairfeedback": updateData.repairfeedback
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{ new: true } // Return the updated document
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!updatedSensor) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ error: 'Slave not found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.status(200).send(updatedSensor);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error(error);
|
|
|
|
|
|
|
|
return reply.status(500).send({ error: 'An error occurred while updating the slave' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.installwaterlevelSensorSlave = async (request, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { storeId } = request.params;
|
|
|
|
|
|
|
|
const { hardwareId, tankhardwareId, dateofinstallation, customerId, installedby } = request.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find the document by storeId and hardwareId, then update the specific slave with tankhardwareId
|
|
|
|
|
|
|
|
const updatedSensor = await WaterLeverSensor.findOneAndUpdate(
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
storeId: storeId,
|
|
|
|
|
|
|
|
hardwareId: hardwareId,
|
|
|
|
|
|
|
|
"slaves.tankhardware.tankhardwareId": tankhardwareId
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
$set: {
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.dateofinstallation": dateofinstallation,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.customerId": customerId,
|
|
|
|
|
|
|
|
"slaves.tankhardware.$.installedby": installedby
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{ new: true } // Return the updated document
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!updatedSensor) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ error: 'Sensor or Slave not found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.status(200).send(updatedSensor);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error(error);
|
|
|
|
|
|
|
|
return reply.status(500).send({ error: 'An error occurred while installing the sensor' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getHardwareqcslave = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
const { storeId } = req.params;
|
|
|
|
|
|
|
|
const { hardwareId, tankhardwareId } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let query;
|
|
|
|
|
|
|
|
if (tankhardwareId) {
|
|
|
|
|
|
|
|
// If tankhardwareId is provided, query for the specific slave
|
|
|
|
|
|
|
|
query = {
|
|
|
|
|
|
|
|
storeId: storeId,
|
|
|
|
|
|
|
|
hardwareId: hardwareId,
|
|
|
|
|
|
|
|
"slaves.tankhardware.tankhardwareId": tankhardwareId,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Otherwise, query for the main hardware
|
|
|
|
|
|
|
|
query = {
|
|
|
|
|
|
|
|
storeId: storeId,
|
|
|
|
|
|
|
|
hardwareId: hardwareId,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const docs = await WaterLeverSensor.find(query).exec();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (docs.length === 0) {
|
|
|
|
|
|
|
|
return reply.status(404).send({ error: 'No hardware found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reply.send({ status_code: 200, data: docs, count: docs.length });
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
|
|
console.error(err);
|
|
|
|
|
|
|
|
reply.status(500).send({ error: 'An error occurred while retrieving the hardware QC data' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|