|
|
|
@ -5,7 +5,8 @@ const bcrypt = require('bcrypt')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fastify = require("fastify");
|
|
|
|
|
const { Tank, MotorData, IotData } = require('../models/tanks')
|
|
|
|
|
const { Tank, MotorData, IotData } = require('../models/tanks');
|
|
|
|
|
const { Deparments } = require('../models/Department');
|
|
|
|
|
const JWT_SECRET = 'your-secret-key';
|
|
|
|
|
|
|
|
|
|
async function generateCustomerId(role) {
|
|
|
|
@ -368,3 +369,56 @@ exports.createUser = async (request, reply) => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDepartmentDetailsByAdminAndName = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
const { adminId } = req.params;
|
|
|
|
|
const { departmentName, reportingManager } = req.body;
|
|
|
|
|
|
|
|
|
|
if (!adminId) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: { error: true, message: "adminId is required in path params" }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!departmentName || !reportingManager) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: { error: true, message: "departmentName and reportingManager are required in body" }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ✅ Find department by adminId, departmentName and reportingManager
|
|
|
|
|
const department = await Deparments.findOne({
|
|
|
|
|
adminId,
|
|
|
|
|
departmentName,
|
|
|
|
|
reportingManager
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
if (!department) {
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
simplydata: { error: true, message: "Department not found with given criteria" }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ✅ Build response data
|
|
|
|
|
const responseData = {
|
|
|
|
|
phone: department.phone,
|
|
|
|
|
firstName: department.firstName,
|
|
|
|
|
lastName: department.lastName,
|
|
|
|
|
email: department.email
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "Department details fetched successfully",
|
|
|
|
|
data: responseData
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching department details:", err);
|
|
|
|
|
reply.status(500).send({
|
|
|
|
|
simplydata: { error: true, message: "Internal server error" }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|