changes in motor data

master^2
Varun 8 months ago
parent 80a4775e2a
commit 2471c903f2

@ -352,15 +352,43 @@ exports.getTanksofParticularInstaller = async (req, reply) => {
exports.getTankmotordata = async (req, reply) => {
try {
await MotorData.find({customerId: req.query.customerId})
.exec()
.then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length });
})
.catch((err) => {
console.log(err);
reply.send({ error: err });
const { startDate, stopDate, block } = req.body;
const { customerId } = req.params;
const start = moment(startDate, "DD-MMM-YYYY - HH:mm").toDate();
const end = moment(stopDate, "DD-MMM-YYYY - HH:mm").toDate();
// Fetch the name from the User collection based on customerId, only from profile
const user = await User.findOne({ customerId })
.select("profile.firstName profile.lastName");
if (user) {
// Get the full name (combine firstName and lastName if available)
const userName = user.profile.firstName && user.profile.lastName
? `${user.profile.firstName} ${user.profile.lastName}`
: "N/A"; // Fallback if no name is found
// Construct the query object for motor data based on customerId
const motorQuery = { customerId };
// If block is provided (and not "All"), add it to the query
if (block !== "All") motorQuery.block = block;
// Fetch motor data for the customerId within the time range
const motorDataDocs = await MotorData.find(motorQuery)
.where("date")
.gte(start) // Greater than or equal to startDate
.lte(end) // Less than or equal to stopDate
.exec();
reply.send({
status_code: 200,
data: motorDataDocs,
count: motorDataDocs.length,
customerName: userName, // Add the username to the response
});
} else {
reply.send({ status_code: 404, message: "User not found" });
}
} catch (err) {
throw boom.boomify(err);
}

@ -821,13 +821,54 @@ module.exports = function (fastify, opts, next) {
handler: tanksController.deletemotordatarecordsbefore7days,
});
fastify.get("/api/getTankmotordata", {
// fastify.get("/api/getTankmotordata", {
// schema: {
// tags: ["Tank"],
// description: "This is for Get Tank Motor Data",
// summary: "This is for to Get Tank Motor Data",
// querystring: {
// customerId: {type: 'string'}
// },
// security: [
// {
// basicAuth: [],
// },
// ],
// },
// preHandler: fastify.auth([fastify.authenticate]),
// handler: tanksController.getTankmotordata,
// });
fastify.route({
method: "PUT",
url: "/api/getTankmotordata/:customerId",
schema: {
tags: ["Tank"],
description: "This is for Get Tank Motor Data",
summary: "This is for to Get Tank Motor Data",
querystring: {
customerId: {type: 'string'}
summary: "This is for Get Tank Motor Data",
params: {
required: ["customerId"],
type: "object",
properties: {
customerId: {
type: "string",
description: "customerId",
},
},
},
body: {
type: "object",
// required: ['phone'],
properties: {
startDate:{ type: "string" },
stopDate:{type:"string"},
block:{type:"string"},
typeofwater:{type:"string"},
},
},
security: [
{
@ -835,7 +876,7 @@ module.exports = function (fastify, opts, next) {
},
],
},
preHandler: fastify.auth([fastify.authenticate]),
//preHandler: fastify.auth([fastify.authenticate]),
handler: tanksController.getTankmotordata,
});
@ -843,6 +884,7 @@ module.exports = function (fastify, opts, next) {
fastify.post('/api/motor/write', {
schema: {
tags: ["Tank"],

Loading…
Cancel
Save