diff --git a/src/controllers/departmentController.js b/src/controllers/departmentController.js index 87c40348..a24b7235 100644 --- a/src/controllers/departmentController.js +++ b/src/controllers/departmentController.js @@ -427,37 +427,53 @@ exports.addDepartment = async (request, reply) => { 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 }); + const cities = await City.distinct('city'); // Fetch distinct city names from the database + + // Normalize the city names to avoid duplicates + const normalizedCities = [...new Set(cities.map(city => city.trim().toUpperCase()))]; + + console.log("Cities fetched:", normalizedCities); // Log the cleaned cities + reply.send({ status_code: 200, data: normalizedCities, count: normalizedCities.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 }); + const zones = await City.distinct('zone'); // Fetch distinct zone names from the database + + // Normalize the zone names to avoid duplicates + const normalizedZones = [...new Set(zones.map(zone => zone.trim().toUpperCase()))]; + + console.log("Zones fetched:", normalizedZones); // Log the cleaned zones + reply.send({ status_code: 200, data: normalizedZones, count: normalizedZones.length }); } catch (err) { - console.error("Error fetching cities:", err); // Log the error for debugging + console.error("Error fetching zones:", err); // Log the error for debugging throw boom.boomify(err); } }; - + exports.getallLocationData = async (req, reply) => { try { - console.log("Fetching all zones..."); // Debug log - const locations = await Deparments.distinct('location'); - reply.send({ status_code: 200, data: locations, count: locations.length }); + console.log("Fetching all locations..."); // Debug log + const locations = await City.distinct('location'); // Fetch distinct locations from the database + + // Normalize the location names to uppercase and remove duplicates + const normalizedLocations = [...new Set(locations.map(location => location.trim().toUpperCase()))]; + + console.log("Locations fetched:", normalizedLocations); // Log the cleaned locations + reply.send({ status_code: 200, data: normalizedLocations, count: normalizedLocations.length }); } catch (err) { - console.error("Error fetching cities:", err); // Log the error for debugging + console.error("Error fetching locations:", err); // Log the error for debugging throw boom.boomify(err); } }; + exports.deletedepartmentInfo = async (req, reply) => { try { const departmentId = req.params.departmentId; diff --git a/src/routes/departmentRoute.js b/src/routes/departmentRoute.js index 78328a01..9ebc96a7 100644 --- a/src/routes/departmentRoute.js +++ b/src/routes/departmentRoute.js @@ -157,8 +157,8 @@ module.exports = function (fastify, opts, next) { url: "/api/departmentSignup", schema: { tags: ["Department"], - description: "This is for creating a new Department Account", - summary: "This is for creating a new Department Account", + description: "This is for creating a new Team Member Account", + summary: "This is for creating a new Ream Member Account", body: { type: "object", //required: ["phone", "username", "password", "role"], // Add role to required fields @@ -239,8 +239,8 @@ module.exports = function (fastify, opts, next) { fastify.get("/api/getallcitiesdata", { schema: { tags: ["Department"], - description: "This is for Get all Cities Data", - summary: "This is for to Get all Cities Data", + description: "This is for Get all Cities Data for City Schema", + summary: "This is for to Get all Cities Data for City Schema", security: [ { @@ -254,8 +254,8 @@ module.exports = function (fastify, opts, next) { fastify.get("/api/getallzonesdata", { schema: { tags: ["Department"], - description: "This is for Get all Zones Data", - summary: "This is for to Get all Zones Data", + description: "This is for Get all Zones Data for City Schema", + summary: "This is for to Get all Zones Data for City Schema", security: [ { @@ -270,8 +270,8 @@ module.exports = function (fastify, opts, next) { fastify.get("/api/getalllocationsdata", { schema: { tags: ["Department"], - description: "This is for Get all Locations Data", - summary: "This is for to Get all Locations Data", + description: "This is for Get all Locations Data for City Schema", + summary: "This is for to Get all Locations Data for City Schema", security: [ {