From 96d71c78ecd209ddb287b84be74eea3cb5b3ce57 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Thu, 24 Jul 2025 12:59:05 +0530 Subject: [PATCH] changes --- src/controllers/installationController.js | 124 +++++++++++++++------- 1 file changed, 86 insertions(+), 38 deletions(-) diff --git a/src/controllers/installationController.js b/src/controllers/installationController.js index 324a5d92..45dc5979 100644 --- a/src/controllers/installationController.js +++ b/src/controllers/installationController.js @@ -140,49 +140,49 @@ exports.createTeamMember = async (req, reply) => { } }; -exports.getAllDepartments = async (request, reply) => { - try { - const { departmentName } = request.params; +// 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", - }, - }); - } +// 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(); +// // ✅ 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", - }, - }); - } +// if (!departments.length) { +// return reply.status(404).send({ +// simplydata: { +// error: true, +// message: "No departments found with the given departmentName", +// }, +// }); +// } - return reply.send({ - simplydata: { - error: false, - message: "Departments retrieved successfully", - data: departments, - }, - }); +// return reply.send({ +// simplydata: { +// error: false, +// message: "Departments retrieved successfully", +// data: departments, +// }, +// }); - } catch (err) { - console.error("Error fetching departments:", err); - return reply.status(500).send({ - simplydata: { - error: true, - message: "Internal server error", - }, - }); - } -}; +// } 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) => { // 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) => { try { const { installationId } = request.params;