allocated sensors

master^2
Bhaskar 7 months ago
parent 870e531dc9
commit 9cc4dc0a2f

@ -3,9 +3,9 @@ const bcrypt = require('bcrypt');
const jwt = require('jsonwebtoken');
const customJwtAuth = require("../customAuthJwt");
const { Deparments } = require("../models/Department");
const { Install, SensorStock, SensorQuotation, Order } = require("../models/store");
const { Install, SensorStock, SensorQuotation, Order, Insensors } = require("../models/store");
const { Counter } = require("../models/User");
const { IotData } = require("../models/tanks");
const { IotData, Tank } = require("../models/tanks");
const fastify = require("fastify")({
logger: true,
//disableRequestLogging: true,
@ -635,4 +635,41 @@ exports.assignTeamMemberToQuotation = async (request, reply) => {
};
exports.getAllocatedSensorsByTank = async (req, reply) => {
try {
let { customerId, tankName } = req.params;
if (!customerId || !tankName) {
return reply.status(400).send({ error: "customerId and tankName are required" });
}
tankName = tankName.trim(); // Trim spaces
console.log("Querying MongoDB with:", { customerId, tankName, status: "blocked" });
const allocatedSensors = await Insensors.find({
customerId,
tankName: { $regex: `^${tankName}$`, $options: "i" }, // Case-insensitive search
status: "blocked",
}).lean();
if (!allocatedSensors.length) {
return reply.send({
status_code: 200,
message: "No allocated sensors found for this tank",
allocatedSensors: [],
});
}
return reply.send({
status_code: 200,
message: "Allocated sensors fetched successfully",
allocatedSensors,
});
} catch (err) {
console.error("Error fetching allocated sensors:", err);
return reply.status(500).send({ error: "Internal server error" });
}
};

@ -260,6 +260,24 @@ module.exports = function (fastify, opts, next) {
},
handler: installationController.getByHardwareAndTankId,
});
fastify.get("/api/getAllocatedSensorsByTank/:customerId/:tankName", {
schema: {
description: "Get allocated sensors by installationId, customerId, and tankName",
tags: ["Installation"],
summary: "Fetch allocated sensors for a given tank",
params: {
type: "object",
properties: {
// installationId: { type: "string" },
customerId: { type: "string" },
tankName: { type: "string" },
},
required: [ "customerId", "tankName"],
},
},
handler: installationController.getAllocatedSensorsByTank,
});
next();

Loading…
Cancel
Save