|
|
|
@ -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" });
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|