|
|
|
@ -932,49 +932,59 @@ exports.getQuotationsByInstallationAndTeamMember = async (request, reply) => {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exports.getDepartmentByFirstName = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
let { firstName } = req.params;
|
|
|
|
|
|
|
|
|
|
if (!firstName) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: { error: true, message: "firstName is required" },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
exports.getDepartmentByFirstName = async (req, reply) => {
|
|
|
|
|
try {
|
|
|
|
|
let { departmentName, firstName } = req.params;
|
|
|
|
|
|
|
|
|
|
// Trim and convert to lowercase
|
|
|
|
|
firstName = firstName.trim().toLowerCase();
|
|
|
|
|
console.log("Searching for firstName:", firstName); // Debugging log
|
|
|
|
|
if (!departmentName) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: { error: true, message: "departmentName is required" },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!firstName) {
|
|
|
|
|
return reply.status(400).send({
|
|
|
|
|
simplydata: { error: true, message: "firstName is required" },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Search for the department with case-insensitive and space-tolerant regex
|
|
|
|
|
const department = await Deparments.findOne({
|
|
|
|
|
firstName: { $regex: `^\\s*${firstName}\\s*$`, $options: "i" }
|
|
|
|
|
}).lean();
|
|
|
|
|
departmentName = departmentName.trim();
|
|
|
|
|
firstName = firstName.trim();
|
|
|
|
|
|
|
|
|
|
console.log("Department found:", department); // Debugging log
|
|
|
|
|
console.log("Searching for:", { departmentName, firstName });
|
|
|
|
|
|
|
|
|
|
if (!department) {
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
simplydata: { error: true, message: "Department not found" },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const department = await Deparments.findOne({
|
|
|
|
|
firstName: { $regex: `^\\s*${firstName}\\s*$`, $options: "i" },
|
|
|
|
|
departmentName: { $regex: `^${departmentName}$`, $options: "i" }
|
|
|
|
|
}).lean();
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "Department details fetched successfully",
|
|
|
|
|
firstName: department.firstName,
|
|
|
|
|
phone: department.phone,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
console.log("Department found:", department);
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching department details:", err);
|
|
|
|
|
return reply.status(500).send({
|
|
|
|
|
simplydata: { error: true, message: "Internal server error" },
|
|
|
|
|
if (!department) {
|
|
|
|
|
return reply.status(404).send({
|
|
|
|
|
simplydata: { error: true, message: "Department not found" },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return reply.send({
|
|
|
|
|
simplydata: {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "Department details fetched successfully",
|
|
|
|
|
firstName: department.firstName,
|
|
|
|
|
phone: department.phone,
|
|
|
|
|
lastName: department.lastName,
|
|
|
|
|
email: department.email
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error("Error fetching department details:", err);
|
|
|
|
|
return reply.status(500).send({
|
|
|
|
|
simplydata: { error: true, message: "Internal server error" },
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const moment = require('moment-timezone');
|
|
|
|
|
|
|
|
|
|