diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index f9d27eec..b3302718 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -132,21 +132,21 @@ 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.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.getAllDepartmentsParticularFields = async (req, reply) => { @@ -423,6 +423,29 @@ exports.addDepartment = async (request, reply) => { throw boom.boomify(err); } }; + + exports.getallCitiesData = async (req, reply) => { + try { + console.log("Fetching all cities..."); // Debug log + const cities = await Deparments.distinct('city'); // Use distinct to get unique cities + console.log("Cities fetched:", cities); // Log the fetched cities + reply.send({ status_code: 200, data: cities, count: cities.length }); + } catch (err) { + console.error("Error fetching cities:", err); // Log the error for debugging + throw boom.boomify(err); + } + }; + + exports.getallZonesData = async (req, reply) => { + try { + console.log("Fetching all zones..."); // Debug log + const zones = await Deparments.distinct('zone'); + reply.send({ status_code: 200, data: zones, count: zones.length }); + } catch (err) { + console.error("Error fetching cities:", err); // Log the error for debugging + throw boom.boomify(err); + } + }; exports.deletedepartmentInfo = async (req, reply) => { try { diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index ece82516..5b51b0fd 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -62,21 +62,21 @@ module.exports = function (fastify, opts, next) { // handler: departmentController.getSinledepartmentData, // }); - fastify.get("/api/getallcities", { - schema: { - tags: ["Department"], - description: "This is for Get all cities Data", - summary: "This is for to Get all cities Data", + // fastify.get("/api/getallcities", { + // schema: { + // tags: ["Department"], + // description: "This is for Get all cities Data", + // summary: "This is for to Get all cities Data", - security: [ - { - basicAuth: [], - }, - ], - }, - //preHandler: fastify.auth([fastify.authenticate]), - handler: departmentController.getallcities, - }); + // security: [ + // { + // basicAuth: [], + // }, + // ], + // }, + // //preHandler: fastify.auth([fastify.authenticate]), + // handler: departmentController.getallcities, + // }); // fastify.get("/api/getalldepartmentsParticularFileds", { @@ -235,7 +235,37 @@ module.exports = function (fastify, opts, next) { //preHandler: fastify.auth([fastify.authenticate]), handler: departmentController.getalldepartments, }); - + + fastify.get("/api/getallcitiesdata", { + schema: { + tags: ["Department"], + description: "This is for Get all Cities Data", + summary: "This is for to Get all Cities Data", + + security: [ + { + basicAuth: [], + }, + ], + }, + //preHandler: fastify.auth([fastify.authenticate]), + handler: departmentController.getallCitiesData, + }); + fastify.get("/api/getallzonesdata", { + schema: { + tags: ["Department"], + description: "This is for Get all Zones Data", + summary: "This is for to Get all Zones Data", + + security: [ + { + basicAuth: [], + }, + ], + }, + //preHandler: fastify.auth([fastify.authenticate]), + handler: departmentController.getallZonesData, + }); fastify.delete("/api/deletedepartment/:departmentId", { schema: { description: "Delete a Department by departmentId",