changes in get batch numbers

master
Varun 9 months ago
parent d4f94b937f
commit b01f54cc92

@ -1251,16 +1251,41 @@ exports.createSensor = async (req, reply) => {
exports.getbatchnumbers = async (req, reply) => {
try {
await Insensors.distinct('batchno', { storeId: req.params.storeId })
const { storeId, type } = req.params;
let prefix = "";
switch (type.toUpperCase()) {
case "SLAVE":
prefix = "SL";
break;
case "MASTER":
prefix = "MA";
break;
case "SENSOR":
prefix = "SN";
break;
case "MOTOR_SWITCH":
prefix = "MS";
break;
default:
reply.send({ status_code: 400, message: "Invalid type" });
return;
}
await Insensors.distinct('batchno', {
storeId: storeId,
batchno: { $regex: `^${prefix}` },
})
.then((batchNumbers) => {
reply.send({ status_code: 200, data: batchNumbers, count: batchNumbers.length });
})
.catch((err) => {
console.log(err);
reply.send({ error: err });
console.error(err);
reply.send({ status_code: 500, error: err });
});
} catch (err) {
reply.send({ error: err });
console.error(err);
reply.send({ status_code: 500, error: err });
}
};

@ -1109,7 +1109,7 @@ fastify.post("/api/createwaterlevelSensorintime/:storeId", {
handler: storeController.createSensor,
})
fastify.get("/api/getbatchnumbers/:storeId", {
fastify.get("/api/getbatchnumbers/:storeId/:type", {
schema: {
tags: ["Store-Data"],
description: "This is to Get batch numbers",
@ -1124,6 +1124,16 @@ fastify.get("/api/getbatchnumbers/:storeId", {
},
},
},
params: {
required: ["type"],
type: "object",
properties: {
type: {
type: "string",
description: "type",
},
},
},
security: [
{
basicAuth: [],

Loading…
Cancel
Save