get all zones and cities

master^2
Bhaskar 9 months ago
parent 6cd325634d
commit 511b790b66

@ -132,21 +132,21 @@ const generateDepartmentId = async (city, departmentName) => {
// } // }
// }; // };
exports.getallcities = async (req, reply) => { // exports.getallcities = async (req, reply) => {
try { // try {
await City.find() // await City.find()
.exec() // .exec()
.then((docs) => { // .then((docs) => {
reply.send({ status_code: 200, data: docs, count: docs.length }); // reply.send({ status_code: 200, data: docs, count: docs.length });
}) // })
.catch((err) => { // .catch((err) => {
console.log(err); // console.log(err);
reply.send({ error: err }); // reply.send({ error: err });
}); // });
} catch (err) { // } catch (err) {
throw boom.boomify(err); // throw boom.boomify(err);
} // }
}; // };
// exports.getAllDepartmentsParticularFields = async (req, reply) => { // exports.getAllDepartmentsParticularFields = async (req, reply) => {
@ -423,6 +423,29 @@ exports.addDepartment = async (request, reply) => {
throw boom.boomify(err); 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) => { exports.deletedepartmentInfo = async (req, reply) => {
try { try {

@ -62,21 +62,21 @@ module.exports = function (fastify, opts, next) {
// handler: departmentController.getSinledepartmentData, // handler: departmentController.getSinledepartmentData,
// }); // });
fastify.get("/api/getallcities", { // fastify.get("/api/getallcities", {
schema: { // schema: {
tags: ["Department"], // tags: ["Department"],
description: "This is for Get all cities Data", // description: "This is for Get all cities Data",
summary: "This is for to Get all cities Data", // summary: "This is for to Get all cities Data",
security: [ // security: [
{ // {
basicAuth: [], // basicAuth: [],
}, // },
], // ],
}, // },
//preHandler: fastify.auth([fastify.authenticate]), // //preHandler: fastify.auth([fastify.authenticate]),
handler: departmentController.getallcities, // handler: departmentController.getallcities,
}); // });
// fastify.get("/api/getalldepartmentsParticularFileds", { // fastify.get("/api/getalldepartmentsParticularFileds", {
@ -235,7 +235,37 @@ module.exports = function (fastify, opts, next) {
//preHandler: fastify.auth([fastify.authenticate]), //preHandler: fastify.auth([fastify.authenticate]),
handler: departmentController.getalldepartments, 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", { fastify.delete("/api/deletedepartment/:departmentId", {
schema: { schema: {
description: "Delete a Department by departmentId", description: "Delete a Department by departmentId",

Loading…
Cancel
Save