master^2
Bhaskar 8 months ago
parent 9a7fb64d02
commit abe3895fff

@ -805,7 +805,19 @@ const getLocationsByCityAndZone = async (city, zone) => {
]);
console.log("Query Result:", result); // Debugging output
return result.length ? result[0] : null; // Return a single object instead of an array
if (result.length) {
let locations = [...new Set(result[0].locations)]; // Remove duplicates
// If zone is "ALL", include "ALL" in the locations list
if (zone.trim().toUpperCase() === "ALL") {
locations.unshift("ALL");
}
return { city, locations };
} else {
return { city, locations: zone.trim().toUpperCase() === "ALL" ? ["ALL"] : [] }; // Return empty if no data
}
} catch (err) {
console.error(err);
throw new Error("Error fetching locations.");
@ -834,6 +846,7 @@ exports.getZonebasedLocations = async (req, reply) => {
};
const getLocationsByZone = async (zone) => {
try {
const result = await City.aggregate([

Loading…
Cancel
Save