ashok 10 months ago
commit f3eff3d734

@ -1165,24 +1165,34 @@ exports.installmotorswitch = async (request, reply) => {
exports.updateSensorById = async (req, reply) => { exports.updateSensorById = async (req, reply) => {
try { try {
const _id = req.params._id; const { _id } = req.params;
const updateData = req.body; const updateData = req.body;
const updatedSensor = await Insensors.findByIdAndUpdate(_id, updateData, { new: true }); const allowedFields = ["model", "type", "hardwareId_company", "hardwareId", "masterId"];
// Filter out unwanted fields
const filteredUpdateData = Object.keys(updateData)
.filter((key) => allowedFields.includes(key))
.reduce((obj, key) => {
obj[key] = updateData[key];
return obj;
}, {});
const updatedSensor = await Insensors.findByIdAndUpdate(_id, filteredUpdateData, { new: true });
if (!updatedSensor) { if (!updatedSensor) {
return reply.code(404).send({ message: 'Sensor not found' }); return reply.code(404).send({ message: "Sensor not found" });
} }
return reply.code(200).send(updatedSensor); return reply.code(200).send(updatedSensor);
} catch (error) { } catch (error) {
console.error('Error updating sensor:', error); console.error("Error updating sensor:", error);
return reply.code(500).send({ message: 'Internal Server Error' }); return reply.code(500).send({ message: "Internal Server Error" });
} }
}; };
exports.getpumpswitchqc = async (req, reply) => { exports.getpumpswitchqc = async (req, reply) => {
try { try {
await MotorSwitchSensor.find({storeId: req.params.storeId,motorId:req.body.motorId}) await MotorSwitchSensor.find({storeId: req.params.storeId,motorId:req.body.motorId})

@ -1112,43 +1112,28 @@ fastify.post("/api/createwaterlevelSensorintime/:storeId", {
fastify.post("/api/updateSensorById/:_id", { fastify.post("/api/updateSensorById/:_id", {
schema: { schema: {
description: "This is for editing Sensors after time", description: "Edit specific sensor fields",
tags: ["Store-Data"], tags: ["Store-Data"],
summary: "This is for editing Sensors after time", summary: "Update specific fields of a sensor before macId",
params: { params: {
required: ["_id"], required: ["_id"],
type: "object", type: "object",
properties: { properties: {
_id: { _id: {
type: "string", type: "string",
description: "storeId", description: "Sensor ID",
}, },
}, },
}, },
body: { body: {
type: "object", type: "object",
properties: { properties: {
batchno: { type: "string", description: "Batch number of the sensor" },
model: { type: "string", description: "Model of the sensor" }, model: { type: "string", description: "Model of the sensor" },
type: { type: "string", description: "Type of sensor" }, type: { type: "string", description: "Type of sensor" },
quantity: { type: "number", description: "Quantity of sensors" },
indate: { type: "string", description: "Date of sensor entry" },
hardwareId_company: { type: "string", description: "Company name of hardware ID" }, hardwareId_company: { type: "string", description: "Company name of hardware ID" },
hardwareId: { type: "string", nullable: true, description: "Hardware ID (if applicable)" }, hardwareId: { type: "string", nullable: true, description: "Hardware ID (if applicable)" },
masterId: { type: "string", nullable: true, description: "Master ID reference" }, masterId: { type: "string", nullable: true, description: "Master ID reference" }
qccheck: { type: "string", nullable: true, description: "QC check status" },
qccheckdate: { type: "string", nullable: true, description: "QC check date" },
qcby: { type: "string", nullable: true, description: "QC checked by" },
comment: { type: "string", default: "0", description: "Comment field" },
outforrepairdate: { type: "string", default: "0", description: "Date sensor sent for repair" },
sendto: { type: "string", nullable: true, description: "Destination for repair" },
repairfeedback: { type: "string", default: "0", description: "Repair feedback" },
dateofinstallation: { type: "string", nullable: true, description: "Installation date" },
installedby: { type: "string", default: "0", description: "Person who installed the sensor" },
customerId: { type: "string", default: "0", description: "Customer ID" },
comments: { type: "string", default: "0", description: "Additional comments" },
sensor_type: { type: "string", enum: ["slaves", "motorswitch", "master"], description: "Type of sensor" }
}, },
}, },
}, },
@ -1156,6 +1141,7 @@ fastify.post("/api/updateSensorById/:_id", {
}); });
fastify.get("/api/getbatchnumbers/:storeId/:type", { fastify.get("/api/getbatchnumbers/:storeId/:type", {
schema: { schema: {
tags: ["Store-Data"], tags: ["Store-Data"],

Loading…
Cancel
Save