commented some functionalities in store

master^2
Varun 8 months ago
parent fc7da09406
commit 483039fda5

@ -722,50 +722,50 @@ exports.editStore = async (request, reply) => {
}; };
const moment = require('moment'); const moment = require('moment');
exports.createwaterlevelSensor = async (req, reply) => { // exports.createwaterlevelSensor = async (req, reply) => {
try { // try {
const storeId = req.params.storeId // const storeId = req.params.storeId
const { hardwareId,hardwareId_company, type, indate } = req.body; // const { hardwareId,hardwareId_company, type, indate } = req.body;
var mater_seq_id = await generatewaterlevelsensorId(); // var mater_seq_id = await generatewaterlevelsensorId();
const date = moment().format('MM-DD'); // const date = moment().format('MM-DD');
const prefix = 'AS' + date + 'MALOV1'; // const prefix = 'AS' + date + 'MALOV1';
var masterId = `${prefix}${mater_seq_id}`; // var masterId = `${prefix}${mater_seq_id}`;
const newSensor = new WaterLeverSensor({ // const newSensor = new WaterLeverSensor({
storeId, // storeId,
hardwareId, // hardwareId,
masterId, // masterId,
type, // type,
indate // indate
}); // });
const savedSensor = await newSensor.save(); // const savedSensor = await newSensor.save();
reply.code(200).send(savedSensor); // reply.code(200).send(savedSensor);
} catch (err) { // } catch (err) {
reply.code(500).send(err); // reply.code(500).send(err);
} // }
}; // };
exports.editWaterLevelSensor = async (req, reply) => { // exports.editWaterLevelSensor = async (req, reply) => {
try { // try {
const { storeId } = req.params; // const { storeId } = req.params;
const updates = req.body; // const updates = req.body;
const updatedSensor = await WaterLeverSensor.findOneAndUpdate( // const updatedSensor = await WaterLeverSensor.findOneAndUpdate(
{ storeId:storeId,hardwareId: req.body.hardwareId }, // { storeId:storeId,hardwareId: req.body.hardwareId },
updates, // updates,
{ new: true } // { new: true }
); // );
if (!updatedSensor) { // if (!updatedSensor) {
reply.code(404).send({ message: "Sensor not found" }); // reply.code(404).send({ message: "Sensor not found" });
} else { // } else {
reply.code(200).send(updatedSensor); // reply.code(200).send(updatedSensor);
} // }
} catch (err) { // } catch (err) {
reply.code(500).send(err); // reply.code(500).send(err);
} // }
}; // };
exports.deleteWaterLevelSensor = async (req, reply) => { exports.deleteWaterLevelSensor = async (req, reply) => {
try { try {
@ -809,28 +809,28 @@ exports.editStore = async (request, reply) => {
} }
}; };
exports.qccheckwaterlevelSensor = async (request, reply) => { // exports.qccheckwaterlevelSensor = async (request, reply) => {
try { // try {
const { hardwareId } = request.params; // const { hardwareId } = request.params;
const updateData = request.body; // const updateData = request.body;
// Find the document by hardwareId and update it with the fields received in the body // // Find the document by hardwareId and update it with the fields received in the body
const updatedSensor = await WaterLeverSensor.findOneAndUpdate( // const updatedSensor = await WaterLeverSensor.findOneAndUpdate(
{ hardwareId: hardwareId }, // { hardwareId: hardwareId },
{ $set: updateData }, // { $set: updateData },
{ new: true } // Return the updated document // { new: true } // Return the updated document
); // );
if (!updatedSensor) { // if (!updatedSensor) {
return reply.status(404).send({ error: 'Sensor not found' }); // return reply.status(404).send({ error: 'Sensor not found' });
} // }
return reply.status(200).send(updatedSensor); // return reply.status(200).send(updatedSensor);
} catch (error) { // } catch (error) {
console.error(error); // console.error(error);
return reply.status(500).send({ error: 'An error occurred while updating the sensor' }); // return reply.status(500).send({ error: 'An error occurred while updating the sensor' });
} // }
}; // };
exports.getHardware = async (req, reply) => { exports.getHardware = async (req, reply) => {
@ -930,39 +930,39 @@ exports.editStore = async (request, reply) => {
exports.editSlave = async (req, reply) => { // exports.editSlave = async (req, reply) => {
try { // try {
const { hardwareId } = req.params; // const { hardwareId } = req.params;
const updates = req.body; // const updates = req.body;
const mainHardware = await WaterLeverSensor.findOne({ hardwareId }); // const mainHardware = await WaterLeverSensor.findOne({ hardwareId });
if (!mainHardware) { // if (!mainHardware) {
reply.code(404).send({ message: "Main hardware not found" }); // reply.code(404).send({ message: "Main hardware not found" });
return; // return;
} // }
const slaveIndex = mainHardware.slaves.tankhardware.findIndex( // const slaveIndex = mainHardware.slaves.tankhardware.findIndex(
(slave) => slave.tankhardwareId === req.body.tankhardwareId // (slave) => slave.tankhardwareId === req.body.tankhardwareId
); // );
if (slaveIndex === -1) { // if (slaveIndex === -1) {
reply.code(404).send({ message: "Slave not found" }); // reply.code(404).send({ message: "Slave not found" });
return; // return;
} // }
mainHardware.slaves.tankhardware[slaveIndex] = { // mainHardware.slaves.tankhardware[slaveIndex] = {
...mainHardware.slaves.tankhardware[slaveIndex], // ...mainHardware.slaves.tankhardware[slaveIndex],
...updates, // ...updates,
}; // };
const updatedHardware = await mainHardware.save(); // const updatedHardware = await mainHardware.save();
reply.code(200).send(updatedHardware); // reply.code(200).send(updatedHardware);
} catch (err) { // } catch (err) {
reply.code(500).send(err); // reply.code(500).send(err);
} // }
}; // };
exports.deleteSlave = async (req, reply) => { exports.deleteSlave = async (req, reply) => {

@ -510,67 +510,67 @@ fastify.get("/api/getusersofParticularInstaller", {
handler: storeController.getusersofParticularInstaller, handler: storeController.getusersofParticularInstaller,
}); });
fastify.post("/api/createwaterlevelSensor/:storeId", { // fastify.post("/api/createwaterlevelSensor/:storeId", {
schema: { // schema: {
description: "This is for creating waterlevel Sensor", // description: "This is for creating waterlevel Sensor",
tags: ["Store-Data"], // tags: ["Store-Data"],
summary: "This is for creating waterlevel Sensor", // summary: "This is for creating waterlevel Sensor",
params: { // params: {
required: ["storeId"], // required: ["storeId"],
type: "object", // type: "object",
properties: { // properties: {
storeId: { // storeId: {
type: "string", // type: "string",
description: "storeId", // description: "storeId",
}, // },
}, // },
}, // },
body: { // body: {
type: "object", // type: "object",
properties: { // properties: {
hardwareId: { type: "string" }, // hardwareId: { type: "string" },
type: { type: "string" }, // type: { type: "string" },
indate: { type: "string" }, // indate: { type: "string" },
hardwareId_company: { type: "string" } // hardwareId_company: { type: "string" }
}, // },
}, // },
}, // },
handler: storeController.createwaterlevelSensor, // handler: storeController.createwaterlevelSensor,
}) // })
fastify.put("/api/editwaterlevelSensor/:storeId", { // fastify.put("/api/editwaterlevelSensor/:storeId", {
schema: { // schema: {
description: "This is for editing a water level sensor", // description: "This is for editing a water level sensor",
tags: ["Store-Data"], // tags: ["Store-Data"],
summary: "This is for editing a water level sensor", // summary: "This is for editing a water level sensor",
params: { // params: {
required: ["storeId"], // required: ["storeId"],
type: "object", // type: "object",
properties: { // properties: {
storeId: { // storeId: {
type: "string", // type: "string",
description: "storeId", // description: "storeId",
}, // },
}, // },
}, // },
body: { // body: {
type: "object", // type: "object",
properties: { // properties: {
hardwareId: { type: "string" }, // hardwareId: { type: "string" },
type: { type: "string" }, // type: { type: "string" },
indate: { type: "string" }, // indate: { type: "string" },
hardwareId_company: { type: "string" } // hardwareId_company: { type: "string" }
}, // },
}, // },
}, // },
handler: storeController.editWaterLevelSensor, // handler: storeController.editWaterLevelSensor,
}); // });
fastify.delete("/api/deletewaterlevelSensor/:storeId", { fastify.delete("/api/deletewaterlevelSensor/:storeId", {
@ -625,37 +625,37 @@ fastify.get("/api/getHardware/:storeId", {
handler: storeController.getHardware, handler: storeController.getHardware,
}); });
fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", { // fastify.post("/api/qccheckwaterlevelSensor/:hardwareId", {
schema: { // schema: {
description: "This is for checking waterlevel Sensor", // description: "This is for checking waterlevel Sensor",
tags: ["Store-Data"], // tags: ["Store-Data"],
summary: "This is for checking waterlevel Sensor", // summary: "This is for checking waterlevel Sensor",
params: { // params: {
required: ["hardwareId"], // required: ["hardwareId"],
type: "object", // type: "object",
properties: { // properties: {
hardwareId: { // hardwareId: {
type: "string", // type: "string",
description: "hardwareId", // description: "hardwareId",
}, // },
}, // },
}, // },
body: { // body: {
type: "object", // type: "object",
properties: { // properties: {
qccheck: { type: "string" }, // qccheck: { type: "string" },
qccheckdate: { type: "string" }, // qccheckdate: { type: "string" },
qcby: { type: "string" }, // qcby: { type: "string" },
comment: { type: "string" }, // comment: { type: "string" },
outforrepairdate: { type: "string" }, // outforrepairdate: { type: "string" },
sendto: { type: "string" }, // sendto: { type: "string" },
repairfeedback: { type: "string" }, // repairfeedback: { type: "string" },
}, // },
}, // },
}, // },
handler: storeController.qccheckwaterlevelSensor, // handler: storeController.qccheckwaterlevelSensor,
}) // })
fastify.put("/api/getHardwareqc/:storeId", { fastify.put("/api/getHardwareqc/:storeId", {
@ -752,45 +752,45 @@ fastify.post("/api/addSlave/:hardwareId", {
}); });
fastify.put("/api/editSlave/:hardwareId", { // fastify.put("/api/editSlave/:hardwareId", {
schema: { // schema: {
description: "This is for editing a slave of a water level sensor", // description: "This is for editing a slave of a water level sensor",
tags: ["Store-Data"], // tags: ["Store-Data"],
summary: "This is for editing a slave of a water level sensor", // summary: "This is for editing a slave of a water level sensor",
params: { // params: {
required: ["hardwareId"], // required: ["hardwareId"],
type: "object", // type: "object",
properties: { // properties: {
hardwareId: { // hardwareId: {
type: "string", // type: "string",
description: "Main hardware ID", // description: "Main hardware ID",
}, // },
}, // },
}, // },
body: { // body: {
type: "object", // type: "object",
properties: { // properties: {
tankhardwareId: { type: "string" }, // tankhardwareId: { type: "string" },
type: { type: "string" }, // type: { type: "string" },
indate: { type: "string" }, // indate: { type: "string" },
hardwareId_company: { type: "string" }, // hardwareId_company: { type: "string" },
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 },
comment: { type: "string", default: "0" }, // comment: { type: "string", default: "0" },
outforrepairdate: { type: "string", default: "0" }, // outforrepairdate: { type: "string", default: "0" },
sendto: { type: "string", default: null }, // sendto: { type: "string", default: null },
repairfeedback: { type: "string", default: "0" }, // repairfeedback: { type: "string", default: "0" },
dateofinstallation: { type: "string", default: null }, // dateofinstallation: { type: "string", default: null },
installedby: { type: "string", default: "0" }, // installedby: { type: "string", default: "0" },
customerId: { type: "string", default: "0" }, // customerId: { type: "string", default: "0" },
comments: { type: "string", default: "0" }, // comments: { type: "string", default: "0" },
}, // },
}, // },
}, // },
handler: storeController.editSlave, // handler: storeController.editSlave,
}); // });
fastify.delete("/api/deleteSlave/:hardwareId", { fastify.delete("/api/deleteSlave/:hardwareId", {

Loading…
Cancel
Save