name based get

master^2
Bhaskar 7 months ago
parent 887f6858de
commit 17ab7921bc

@ -530,4 +530,49 @@ exports.assignTeamMemberToQuotation = 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" },
});
}
// Trim and convert to lowercase
firstName = firstName.trim().toLowerCase();
console.log("Searching for firstName:", firstName); // Debugging log
// Search for the department with case-insensitive and space-tolerant regex
const department = await Deparments.findOne({
firstName: { $regex: `^\\s*${firstName}\\s*$`, $options: "i" }
}).lean();
console.log("Department found:", department); // Debugging log
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,
},
});
} catch (err) {
console.error("Error fetching department details:", err);
return reply.status(500).send({
simplydata: { error: true, message: "Internal server error" },
});
}
};

@ -212,6 +212,22 @@ module.exports = function (fastify, opts, next) {
handler: installationController.deleteTeamMember
});
fastify.get("/api/getDepartmentByFirstName/:firstName", {
schema: {
description: "Get department details by first name",
tags: ["Installation"],
summary: "Fetch department's firstName and phone",
params: {
type: "object",
properties: {
firstName: { type: "string", description: "Department's first name" },
},
required: ["firstName"],
},
},
handler: installationController.getDepartmentByFirstName,
});
next();

Loading…
Cancel
Save