LORA and GSM check apis

master^2
Bhaskar 7 months ago
parent 5bb68828cb
commit e43767b9b0

@ -4,7 +4,8 @@ const jwt = require('jsonwebtoken');
const customJwtAuth = require("../customAuthJwt"); const customJwtAuth = require("../customAuthJwt");
const { Deparments } = require("../models/Department"); const { Deparments } = require("../models/Department");
const { Install, SensorStock, SensorQuotation, Order } = require("../models/store"); const { Install, SensorStock, SensorQuotation, Order } = require("../models/store");
const { Counter } = require("../models/User") const { Counter } = require("../models/User");
const { IotData } = require("../models/tanks");
const fastify = require("fastify")({ const fastify = require("fastify")({
logger: true, logger: true,
//disableRequestLogging: true, //disableRequestLogging: true,
@ -576,3 +577,62 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
}; };
exports.getByHardwareId = async (req, reply) => {
try {
const { hardwareId } = req.params;
if (!hardwareId) {
return reply.status(400).send({ error: "hardwareId is required" });
}
console.log("Fetching details for hardwareId:", hardwareId);
// Fetch only required fields to reduce response size
// const data = await Collection.findOne({ hardwareId })
// .select("hardwareId mode tanks date time") // Select only needed fields
// .lean();
const data = await IotData.find({ hardwareId });
if (!data) {
return reply.send({ status_code: 404, message: "Data not found", data: null });
}
return reply.send({ status_code: 200, message: "Success", data });
} catch (err) {
console.error("Error:", err);
return reply.status(500).send({ error: "Internal Server Error" });
}
};
exports.getByHardwareAndTankId = async (req, reply) => {
try {
const { hardwareId, tankhardwareId } = req.params;
if (!hardwareId || !tankhardwareId) {
return reply.status(400).send({ error: "Both hardwareId and tankhardwareId are required" });
}
console.log("Fetching details for:", { hardwareId, tankhardwareId });
// Correct query using $elemMatch
const data = await IotData.findOne(
{ hardwareId, tanks: { $elemMatch: { tankhardwareId } } },
{ "tanks.$": 1, hardwareId: 1, mode: 1, date: 1, time: 1 } // Projection to return only matched tank
);
if (!data) {
return reply.send({ status_code: 404, message: "Data not found", data: null });
}
return reply.send({ status_code: 200, message: "Success", data });
} catch (err) {
console.error("Error:", err);
return reply.status(500).send({ error: "Internal Server Error" });
}
};

@ -228,6 +228,38 @@ module.exports = function (fastify, opts, next) {
handler: installationController.getDepartmentByFirstName, handler: installationController.getDepartmentByFirstName,
}); });
fastify.get("/api/getGsmCheck/:hardwareId", {
schema: {
description: "Get GSM check details",
tags: ["Installation"],
summary: "Get GSM check details",
params: {
type: "object",
properties: {
hardwareId: { type: "string" },
},
required: ["hardwareId"],
},
},
handler: installationController.getByHardwareId,
});
fastify.get("/api/getLoraCheck/:hardwareId/:tankhardwareId", {
schema: {
description: "Get LORA check details",
tags: ["Installation"],
summary: "Get LORA check details",
params: {
type: "object",
properties: {
hardwareId: { type: "string" },
tankhardwareId: { type : "string"},
},
required: ["hardwareId","tankhardwareId"],
},
},
handler: installationController.getByHardwareAndTankId,
});
next(); next();

Loading…
Cancel
Save