Bhaskar 7 months ago
commit 7b4d3b8d8a

@ -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' });
} }
}; };

@ -336,12 +336,12 @@ const motorSwitchSensorInSchema = new mongoose.Schema({
const insensorsSchema = new mongoose.Schema({ const insensorsSchema = new mongoose.Schema({
storeId: { type: String }, storeId: { type: String },
hardwareId: { type: String ,default:null}, hardwareId: { type: String, default: null },
masterId: { type: String, default: null }, masterId: { type: String, default: null },
type: { type: String }, type: { type: String },
model: { type: String }, model: { type: String },
indate: { type: String }, indate: { type: String },
hardwareId_company: { type: String,default: null }, hardwareId_company: { type: String, default: null },
qccheck: { type: String, default: null }, qccheck: { type: String, default: null },
qccheckdate: { type: String, default: null }, qccheckdate: { type: String, default: null },
qcby: { type: String, default: null }, qcby: { type: String, default: null },
@ -355,11 +355,34 @@ const insensorsSchema = new mongoose.Schema({
comments: { type: String, default: "0" }, comments: { type: String, default: "0" },
quantity: { type: Number, default: 0 }, quantity: { type: Number, default: 0 },
batchno: { type: String, default: null }, batchno: { type: String, default: null },
sensor_type: { type: String, enum: ['slaves', 'motorswitch', 'master'] }, // adding sensor_type field sensor_type: { type: String }, // adding sensor_type field
status: { type: String, default: "pending" }, status: { type: String, default: "pending" },
quality_check_details: [{
damage_check: { result: String },
stickering_check: { result: String },
power_check: { result: String },
master_connecting_gsm: { result: String },
slave_connecting: { result: String },
motor_starting: {
result: String,
steps: [
{ step: Number, result: String }
]
},
connecting_to_sensor: { result: String },
connecting_to_slave: { result: String },
data_sending: { result: String },
distance_check: {
result: String,
steps: [
{ step: Number, result: String }
]
}
}]
}); });
const iotpriceSchema = new mongoose.Schema({ const iotpriceSchema = new mongoose.Schema({
name: { type: String }, name: { type: String },
type: { type: String ,default:null}, type: { type: String ,default:null},

@ -1158,6 +1158,30 @@ fastify.post('/api/generateHardwareMasterId/:storeId', {
handler: storeController.generateHardwareMasterId, handler: storeController.generateHardwareMasterId,
}); });
fastify.post('/api/getSensorByHardwareId/:storeId', {
schema: {
description: 'Fetch details of a specific sensor using hardwareId',
tags: ['Store-Data'],
summary: 'Retrieve sensor details by hardwareId',
params: {
required: ['storeId'],
type: 'object',
properties: {
storeId: { type: 'string', description: 'Store ID' },
},
},
body: {
type: 'object',
required: ['hardwareId'],
properties: {
hardwareId: { type: 'string', description: 'Hardware ID of the sensor' },
},
},
},
handler: storeController.getSensorByHardwareId,
});
fastify.post("/api/updateSensorById/:_id", { fastify.post("/api/updateSensorById/:_id", {
schema: { schema: {
description: "Edit specific sensor fields", description: "Edit specific sensor fields",
@ -1189,30 +1213,75 @@ fastify.post("/api/updateSensorById/:_id", {
}); });
fastify.post("/api/updateSensorQC/:_id", { fastify.post('/api/updateSensorQC/:_id', {
schema: { schema: {
description: "Edit specific sensor QC fields", description: 'Edit specific sensor QC fields',
tags: ["Store-Data"], tags: ['Store-Data'],
summary: "Update QC fields of a sensor", summary: 'Update QC fields of a sensor',
params: { params: {
required: ["_id"], required: ['_id'],
type: "object", type: 'object',
properties: { properties: {
_id: { _id: { type: 'string', description: 'Sensor ID' },
type: "string",
description: "Sensor ID",
},
}, },
}, },
body: { body: {
type: "object", type: 'object',
properties: { properties: {
qccheck: { type: "string", description: "QC check status" }, qccheck: { type: 'string', description: 'QC check status' },
qcby: { type: "string", description: "QC checked by" }, qcby: { type: 'string', description: 'QC checked by' },
comments: { type: "string", description: "QC comment" }, comments: { type: 'string', description: 'QC comment' },
quality_check_details: {
}, type: 'array',
}, description: 'Detailed quality check results',
items: {
type: 'object',
properties: {
damage_check: { type: 'string' },
stickering_check: { type: 'string' },
power_check: { type: 'string' },
master_connecting_gsm: { type: 'string' },
slave_connecting: { type: 'string' },
motor_starting: {
type: 'object',
properties: {
result: { type: 'string' },
steps: {
type: 'array',
items: {
type: 'object',
properties: {
step: { type: 'number' },
result: { type: 'string' }
}
}
}
}
},
connecting_to_sensor: { type: 'string' },
connecting_to_slave: { type: 'string' },
data_sending: { type: 'string' },
distance_check: {
type: 'object',
properties: {
result: { type: 'string' },
steps: {
type: 'array',
items: {
type: 'object',
properties: {
step: { type: 'number' },
result: { type: 'string' }
}
}
}
}
}
}
}
}
}
}
}, },
handler: storeController.updateSensorQC, handler: storeController.updateSensorQC,
}); });

Loading…
Cancel
Save