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