|
|
|
@ -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;
|
|
|
|
|