From 640ff2788b79f897771404552d447550a3b42af0 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Wed, 11 Dec 2024 10:38:37 +0530 Subject: [PATCH] get all designations particular fileds --- src/controllers/departmentController.js | 31 +++++++++++++++++++++++++ src/routes/departmentRoute.js | 16 +++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index ef9ed9ce..36ae99e3 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -135,6 +135,9 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => { cities: [...new Set(departments.map((doc) => doc.city))], zones: [...new Set(departments.map((doc) => doc.zone))], pincodes: [...new Set(departments.map((doc) => doc.pincode))], + departments: [...new Set(departments.map((doc) => doc.departmentName))], + states: [...new Set(departments.map((doc) => doc.state))], + countries: [...new Set(departments.map((doc) => doc.country))], }; // Sending the response @@ -393,3 +396,31 @@ exports.getAllDepartmentsParticularFields = async (req, reply) => { reply.status(500).send({ message: err.message }); } }; + exports.getAllDesignationsParticularFields = async (req, reply) => { + try { + const departments = await Desgination.find().exec(); + + // Grouping the data + const result = { + cities: [...new Set(departments.map((doc) => doc.city))], + zones: [...new Set(departments.map((doc) => doc.zone))], + pincodes: [...new Set(departments.map((doc) => doc.pincode))], + departments: [...new Set(departments.map((doc) => doc.departmentName))], + states: [...new Set(departments.map((doc) => doc.state))], + countries: [...new Set(departments.map((doc) => doc.country))], + designations: [...new Set(departments.map((doc) => doc.desginationName))], + reportingMangers: [...new Set(departments.map((doc) => doc.reportingManager))], + + }; + + // Sending the response + reply.send({ + status_code: 200, + data: result, + count: departments.length, + }); + } catch (err) { + console.error(err); + reply.send({ error: err.message }); + } + }; \ No newline at end of file diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index 65564b75..fe6df2fb 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -287,6 +287,22 @@ module.exports = function (fastify, opts, next) { }, handler: departmentController.editdesgination, }); + + fastify.get("/api/getalldesignationsParticularFileds", { + schema: { + tags: ["Department"], + description: "This is for Get all Designation particular fileds Data", + summary: "This is for to Get all Designation particular fields Data", + + security: [ + { + basicAuth: [], + }, + ], + }, + //preHandler: fastify.auth([fastify.authenticate]), + handler: departmentController.getAllDesignationsParticularFields, + }); next(); }; \ No newline at end of file