master^2
Bhaskar 2 months ago
parent 7184fb1cb0
commit 96d71c78ec

@ -140,49 +140,49 @@ exports.createTeamMember = async (req, reply) => {
} }
}; };
exports.getAllDepartments = async (request, reply) => { // exports.getAllDepartments = async (request, reply) => {
try { // try {
const { departmentName } = request.params; // const { departmentName } = request.params;
if (!departmentName) { // if (!departmentName) {
return reply.status(400).send({ // return reply.status(400).send({
simplydata: { // simplydata: {
error: true, // error: true,
message: "departmentName is required in path params", // message: "departmentName is required in path params",
}, // },
}); // });
} // }
// ✅ Find all departments matching departmentName // // ✅ Find all departments matching departmentName
const departments = await Deparments.find({ departmentName }).lean(); // const departments = await Deparments.find({ departmentName }).lean();
if (!departments.length) { // if (!departments.length) {
return reply.status(404).send({ // return reply.status(404).send({
simplydata: { // simplydata: {
error: true, // error: true,
message: "No departments found with the given departmentName", // message: "No departments found with the given departmentName",
}, // },
}); // });
} // }
return reply.send({ // return reply.send({
simplydata: { // simplydata: {
error: false, // error: false,
message: "Departments retrieved successfully", // message: "Departments retrieved successfully",
data: departments, // data: departments,
}, // },
}); // });
} catch (err) { // } catch (err) {
console.error("Error fetching departments:", err); // console.error("Error fetching departments:", err);
return reply.status(500).send({ // return reply.status(500).send({
simplydata: { // simplydata: {
error: true, // error: true,
message: "Internal server error", // message: "Internal server error",
}, // },
}); // });
} // }
}; // };
// exports.assignTeamMemberToQuotation = async (request, reply) => { // exports.assignTeamMemberToQuotation = async (request, reply) => {
// try { // try {
@ -250,6 +250,54 @@ exports.getAllDepartments = async (request, reply) => {
// } // }
// }; // };
exports.getAllDepartments = async (request, reply) => {
try {
const { departmentName } = request.params;
if (!departmentName) {
return reply.status(400).send({
simplydata: {
error: true,
message: "departmentName is required in path params",
},
});
}
// Find all departments matching departmentName
const departments = await Deparments.find({ departmentName }).lean();
if (!departments.length) {
return reply.status(404).send({
simplydata: {
error: true,
message: "No departments found with the given departmentName",
},
});
}
// Add extra object { firstName: "Self" } at start
const extraObject = { firstName: "Self" };
const responseData = [extraObject, ...departments];
return reply.send({
simplydata: {
error: false,
message: "Departments retrieved successfully",
data: responseData,
},
});
} catch (err) {
console.error("Error fetching departments:", err);
return reply.status(500).send({
simplydata: {
error: true,
message: "Internal server error",
},
});
}
};
exports.assignTeamMemberToQuotation = async (request, reply) => { exports.assignTeamMemberToQuotation = async (request, reply) => {
try { try {
const { installationId } = request.params; const { installationId } = request.params;

Loading…
Cancel
Save