Skip to content

Commit

Permalink
Merge pull request #170 from OpenLMIS-Angola/OAM-291-cache-ward-valid…
Browse files Browse the repository at this point in the history
…-sources

OAM-291: added caching vs for wards
  • Loading branch information
DominikNoga authored Aug 13, 2024
2 parents fb74269 + 06bca54 commit c80df64
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,11 @@ describe('StockAdjustmentCreationController', function() {
});

it('should redirect with proper state params after success', function() {
console.log('test start');
spyOn(stockAdjustmentCreationService, 'submitAdjustments');
stockAdjustmentCreationService.submitAdjustments.andReturn(q.resolve());
vm.submit();
rootScope.$apply();

console.log('test end - before expect');

expect(alertService.error).not.toHaveBeenCalled();
});

Expand Down
28 changes: 25 additions & 3 deletions src/stock-valid-sources/source-cache.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
.module('stock-valid-sources')
.run(routes);

routes.$inject = ['loginService', 'sourceDestinationService', 'facilityFactory', '$q'];
routes.$inject = ['loginService', 'sourceDestinationService', 'facilityFactory', '$q', 'wardService',
'WARDS_CONSTANTS'];

function routes(loginService, sourceDestinationService, facilityFactory, $q) {
function routes(loginService, sourceDestinationService, facilityFactory, $q, wardService,
WARDS_CONSTANTS) {

loginService.registerPostLoginAction(function() {
sourceDestinationService.clearSourcesCache();
Expand All @@ -42,12 +44,32 @@
homeFacility.id ? homeFacility.id : homeFacility
);

return sources;
return getHomeFacilityWards(homeFacility)
.then(function(response) {
var wards = response.content;
if (wards.length) {
var wardsPromise = sourceDestinationService
.getSourceAssignments(supportedProgramsIds, wards[0].id);
return $q.all([sources, wardsPromise]);
}
return sources;
})
.catch(function() {
return sources;
});
})
.catch(function() {
return $q.resolve();
});
});

function getHomeFacilityWards(homeFacility) {
return wardService.getWardsByFacility({
zoneId: homeFacility.geographicZone.id,
sort: 'code,asc',
type: WARDS_CONSTANTS.WARD_TYPE_CODE
});
}
}

})();

0 comments on commit c80df64

Please sign in to comment.