qc and get qc and installation for slaves

master
varun 1 year ago
parent 937570b4b6
commit a3f038d027

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

@ -217,6 +217,40 @@ fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", {
handler: storeController.qccheckwaterlevelSensor, handler: storeController.qccheckwaterlevelSensor,
}) })
fastify.post("/api/qccheckwaterlevelslaveSensor/:storeId", {
schema: {
description: "This is for checking waterlevel Sensor slaves",
tags: ["Store-Data"],
summary: "This is for checking waterlevel Sensor slaves",
params: {
required: ["storeId"],
type: "object",
properties: {
storeId: {
type: "string",
description: "Store ID",
},
},
},
body: {
type: "object",
properties: {
tankhardwareId: { type: "string" },
qccheck: { type: "string" },
qccheckdate: { type: "string" },
qcby: { type: "string" },
comment: { type: "string" },
outforrepairdate: { type: "string" },
sendto: { type: "string" },
repairfeedback: { type: "string" },
},
},
},
handler: storeController.qccheckwaterlevelSensorSlave,
});
fastify.get("/api/getHardware/:storeId", { fastify.get("/api/getHardware/:storeId", {
schema: { schema: {
@ -305,5 +339,67 @@ fastify.post("/api/addSlave/:hardwareId", {
}); });
fastify.post("/api/installwaterlevelSensorSlave/:storeId", {
schema: {
description: "This is for installing waterlevel Sensor Slaves",
tags: ["Store-Data"],
summary: "This is for installing waterlevel Sensor Slaves",
params: {
required: ["storeId"],
type: "object",
properties: {
storeId: {
type: "string",
description: "Store ID",
},
},
},
body: {
type: "object",
properties: {
hardwareId: { type: "string" },
tankhardwareId: { type: "string" }, // Add tankhardwareId in body
dateofinstallation: { type: "string" },
customerId: { type: "string" },
installedby: { type: "string" }
},
},
},
handler: storeController.installwaterlevelSensorSlave,
});
fastify.put("/api/getHardwareqcslave/:storeId", {
schema: {
tags: ["Store-Data"],
description: "This is to Get Quality Check Hardware Data Slave",
summary: "This is to Get Quality Check Hardware Data slave",
params: {
required: ["storeId"],
type: "object",
properties: {
storeId: {
type: "string",
description: "Store ID",
},
},
},
body: {
type: "object",
properties: {
hardwareId: { type: "string" },
tankhardwareId: { type: "string" }, // Optional field for tank hardware
},
},
security: [
{
basicAuth: [],
},
],
},
handler: storeController.getHardwareqcslave,
});
next(); next();
}; };

Loading…
Cancel
Save