diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index b33c1a98..9b5538b9 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -201,21 +201,24 @@ const generateDepartmentId = async (city, departmentName) => { // } // }; - // exports.getallcities = async (req, reply) => { - // try { - // await City.find() - // .exec() - // .then((docs) => { - // reply.send({ status_code: 200, data: docs, count: docs.length }); - // }) - // .catch((err) => { - // console.log(err); - // reply.send({ error: err }); - // }); - // } catch (err) { - // throw boom.boomify(err); - // } - // }; +exports.getallCompanyNames = async (req, reply) => { + try { + await City.find() + .select("officeName -_id") // Select only officeName and exclude _id + .exec() + .then((docs) => { + const officeNames = docs.map((doc) => doc.officeName); // Extract only officeName values + reply.send({ status_code: 200, data: officeNames, count: officeNames.length }); + }) + .catch((err) => { + console.log(err); + reply.send({ error: err }); + }); + } catch (err) { + throw boom.boomify(err); + } +}; + // exports.getAllDepartmentsParticularFields = async (req, reply) => { diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index d6141424..2911456b 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -96,6 +96,23 @@ module.exports = function (fastify, opts, next) { // handler: departmentController.getAllDepartmentsParticularFields, // }); + fastify.get("/api/getallcompanyNames", { + schema: { + tags: ["Department"], + description: "This is for Get all Company Name in city schema ", + summary: "This is for to Get all Company Name in city schema ", + + security: [ + { + basicAuth: [], + }, + ], + }, + //preHandler: fastify.auth([fastify.authenticate]), + handler: departmentController.getallCompanyNames, + }); + + fastify.delete("/api/deletecity/:cityId", { schema: { description: "Delete a city by cityId",