Skip to content

Commit

Permalink
SELV3-780: automatically findd the lowest geo level (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
olewandowski1 authored Dec 13, 2024
1 parent 353f593 commit 00ccf6b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@

geoZoneCatchmentPopulationService.$inject = [
'featureFlagService',
'GeographicLevelService',
'GeoLevelResource',
'CATCHMENT_POPULATION_CALC_AUTO_FEATURE_FLAG'
];

function geoZoneCatchmentPopulationService(
featureFlagService,
GeographicLevelService,
GeoLevelResource,
CATCHMENT_POPULATION_CALC_AUTO_FEATURE_FLAG
) {
const isCatchmentPopulationAutoCalc = featureFlagService.get(CATCHMENT_POPULATION_CALC_AUTO_FEATURE_FLAG);
const lowestLevel = GeographicLevelService.getTheLowestLevelNumber();
let lowestLevel = null;

new GeoLevelResource().getTheLowestGeoLevel()
.then(function(geoLevel) {
lowestLevel = geoLevel.levelNumber;
});

return {
isEditable: function(geographicZone) {
Expand Down
18 changes: 18 additions & 0 deletions src/referencedata-geographic-level/geo-level-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
});
}

GeoLevelResource.prototype.getTheLowestGeoLevel = getTheLowestGeoLevel;

return GeoLevelResource;

function getTheLowestGeoLevel() {
return new Promise(function(resolve) {
new GeoLevelResource().query()
.then(function(resource) {
const lowestGeoLevel = resource.content.reduce(function(lowestGeoLevel, geoLevel) {
// Compare and keep the one with the highest `levelNumber` value
return geoLevel.levelNumber > lowestGeoLevel.levelNumber
? geoLevel : lowestGeoLevel;
});

resolve(lowestGeoLevel);
});
});
}

}
})();
52 changes: 0 additions & 52 deletions src/referencedata-geographic-level/geographic-level.service.js

This file was deleted.

0 comments on commit 00ccf6b

Please sign in to comment.