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

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

Loading…
Cancel
Save