|
|
@ -1228,7 +1228,28 @@ exports.generateHardwareMasterId = async (req, reply) => {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getSensorByHardwareId = async (req, reply) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { storeId } = req.params;
|
|
|
|
|
|
|
|
const { hardwareId } = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!hardwareId) {
|
|
|
|
|
|
|
|
return reply.code(400).send({ message: 'hardwareId is required' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sensor = await Insensors.findOne({ storeId, hardwareId });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sensor) {
|
|
|
|
|
|
|
|
return reply.code(404).send({ message: 'Sensor not found' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return reply.code(200).send(sensor);
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
console.error('Error fetching sensor by hardwareId:', error);
|
|
|
|
|
|
|
|
return reply.code(500).send({ message: 'Internal Server Error' });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
exports.updateSensorById = async (req, reply) => {
|
|
|
|
exports.updateSensorById = async (req, reply) => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -1283,7 +1304,7 @@ exports.updateSensorQC = async (req, reply) => {
|
|
|
|
const { _id } = req.params;
|
|
|
|
const { _id } = req.params;
|
|
|
|
let updateData = req.body;
|
|
|
|
let updateData = req.body;
|
|
|
|
|
|
|
|
|
|
|
|
const allowedFields = ["qccheck", "qcby", "comment", "status"];
|
|
|
|
const allowedFields = ['qccheck', 'qcby', 'comment', 'status', 'quality_check_details'];
|
|
|
|
|
|
|
|
|
|
|
|
// Filter only allowed fields
|
|
|
|
// Filter only allowed fields
|
|
|
|
const filteredUpdateData = Object.keys(updateData)
|
|
|
|
const filteredUpdateData = Object.keys(updateData)
|
|
|
@ -1296,11 +1317,11 @@ exports.updateSensorQC = async (req, reply) => {
|
|
|
|
// Ensure qccheck is handled properly
|
|
|
|
// Ensure qccheck is handled properly
|
|
|
|
if (filteredUpdateData.qccheck) {
|
|
|
|
if (filteredUpdateData.qccheck) {
|
|
|
|
const qccheckLower = filteredUpdateData.qccheck.toLowerCase();
|
|
|
|
const qccheckLower = filteredUpdateData.qccheck.toLowerCase();
|
|
|
|
filteredUpdateData.status = qccheckLower === "ok" ? "available" : "qcfailed";
|
|
|
|
filteredUpdateData.status = qccheckLower === 'ok' ? 'available' : 'qcfailed';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format
|
|
|
|
// Update qccheckdate with the current date in "DD-MMM-YYYY - HH:MM" format
|
|
|
|
filteredUpdateData.qccheckdate = moment().format("DD-MMM-YYYY - HH:mm");
|
|
|
|
filteredUpdateData.qccheckdate = moment().format('DD-MMM-YYYY - HH:mm');
|
|
|
|
|
|
|
|
|
|
|
|
// Find the sensor by ID
|
|
|
|
// Find the sensor by ID
|
|
|
|
const updatedSensor = await Insensors.findByIdAndUpdate(
|
|
|
|
const updatedSensor = await Insensors.findByIdAndUpdate(
|
|
|
@ -1310,14 +1331,14 @@ exports.updateSensorQC = async (req, reply) => {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if (!updatedSensor) {
|
|
|
|
if (!updatedSensor) {
|
|
|
|
return reply.code(404).send({ message: "Sensor not found" });
|
|
|
|
return reply.code(404).send({ message: 'Sensor not found' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update stock based on QC result
|
|
|
|
// Update stock based on QC result
|
|
|
|
const stockRecord = await SensorStock.findOne({ storeId: updatedSensor.storeId, type: updatedSensor.type });
|
|
|
|
const stockRecord = await SensorStock.findOne({ storeId: updatedSensor.storeId, type: updatedSensor.type });
|
|
|
|
|
|
|
|
|
|
|
|
if (stockRecord) {
|
|
|
|
if (stockRecord) {
|
|
|
|
if (filteredUpdateData.qccheck && filteredUpdateData.qccheck.toLowerCase() === "ok") {
|
|
|
|
if (filteredUpdateData.qccheck && filteredUpdateData.qccheck.toLowerCase() === 'ok') {
|
|
|
|
// If QC is "ok", move 1 from total_count_before_qc to total_available
|
|
|
|
// If QC is "ok", move 1 from total_count_before_qc to total_available
|
|
|
|
await SensorStock.updateOne(
|
|
|
|
await SensorStock.updateOne(
|
|
|
|
{ storeId: updatedSensor.storeId, type: updatedSensor.type },
|
|
|
|
{ storeId: updatedSensor.storeId, type: updatedSensor.type },
|
|
|
@ -1334,8 +1355,8 @@ exports.updateSensorQC = async (req, reply) => {
|
|
|
|
|
|
|
|
|
|
|
|
return reply.code(200).send(updatedSensor);
|
|
|
|
return reply.code(200).send(updatedSensor);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Error updating QC fields:", error);
|
|
|
|
console.error('Error updating QC fields:', error);
|
|
|
|
return reply.code(500).send({ message: "Internal Server Error" });
|
|
|
|
return reply.code(500).send({ message: 'Internal Server Error' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|