diff --git a/backend/src/routes/cache-router.js b/backend/src/routes/cache-router.js index 63227a00e..95c166126 100644 --- a/backend/src/routes/cache-router.js +++ b/backend/src/routes/cache-router.js @@ -8,31 +8,31 @@ const constants = require('../util/constants'); const extendSession = utils.extendSession(); -router.get('/district/:districtId', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedDistrictByDistrictId); +router.get('/district/:districtId', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedDistrictByDistrictId); -router.get('/district', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedDistricts); +router.get('/district', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedDistricts); -router.get('/school', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedSchools); +router.get('/school', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedSchools); -router.get('/school/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedSchoolBySchoolID); +router.get('/school/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedSchoolBySchoolID); -router.get('/authority', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedAuthorities); +router.get('/authority', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedAuthorities); -router.get('/authority/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedAuthorityByAuthorityID); +router.get('/authority/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedAuthorityByAuthorityID); -router.get('/school-category-facility-type', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedSchoolCategoryFacilityTypes); +router.get('/school-category-facility-type', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedSchoolCategoryFacilityTypes); -router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL')); +router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL')); -router.get('/district-contact-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.DISTRICT_CONTACT_TYPE_CODES,'server:institute:facilityTypeURL')); +router.get('/district-contact-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.DISTRICT_CONTACT_TYPE_CODES,'server:institute:facilityTypeURL')); -router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL')); +router.get('/facility-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.FACILITY_TYPES,'server:institute:facilityTypeURL')); -router.get('/school-category-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_CATEGORY_TYPES,'server:institute:categoryCodesURL')); +router.get('/school-category-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_CATEGORY_TYPES,'server:institute:categoryCodesURL')); -router.get('/school-organization-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession,getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_ORGANIZATION_TYPES,'server:institute:organizationCodeURL')); +router.get('/school-organization-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_ORGANIZATION_TYPES,'server:institute:organizationCodeURL')); -router.get('/school-neighborhood-learning-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_NEIGHBOURHOOD_LEARNING_TYPES,'server:institute:neighbourhoodLearningURL')); +router.get('/school-neighborhood-learning-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.SCHOOL_NEIGHBOURHOOD_LEARNING_TYPES,'server:institute:neighbourhoodLearningURL')); router.get('/authority-types', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, utils.cacheMiddleware(), getCachedInstituteData(constants.CACHE_KEYS.AUTHORITY_TYPES,'server:institute:authorityTypeCodesURL')); diff --git a/frontend/src/components/Home.vue b/frontend/src/components/Home.vue index e581ab151..b4641139f 100644 --- a/frontend/src/components/Home.vue +++ b/frontend/src/components/Home.vue @@ -380,7 +380,7 @@ export default { } }, async beforeMount() { - await appStore().getCodes(); + await appStore().getInstituteCodes(); }, mounted() { if (this.VIEW_EDIT_PEN_REQUEST_BATCH_FILES_ROLE) { diff --git a/frontend/src/components/data-collection/StepOneCloseCollection.vue b/frontend/src/components/data-collection/StepOneCloseCollection.vue index d6447c7e0..bce15a249 100644 --- a/frontend/src/components/data-collection/StepOneCloseCollection.vue +++ b/frontend/src/components/data-collection/StepOneCloseCollection.vue @@ -143,7 +143,7 @@ export default { ...mapState(appStore, ['collectionTypeCodesMap']), }, async created() { - await appStore().getCodes().then(() => { + await appStore().getSdcCodes().then(() => { this.collectionTypesMap = this.collectionTypeCodesMap; this.collectionTypesMap.forEach((type) => { this.collectionTypes.push(type['label']); diff --git a/frontend/src/components/institute/common/SchoolFunding.vue b/frontend/src/components/institute/common/SchoolFunding.vue index f2b8cb94c..ff5867e8f 100644 --- a/frontend/src/components/institute/common/SchoolFunding.vue +++ b/frontend/src/components/institute/common/SchoolFunding.vue @@ -260,7 +260,7 @@ export default { }, mounted() { instituteStore().getAllGradeCodes(); - appStore().getCodes().then(() => { + appStore().getSdcCodes().then(() => { this.schoolFundingGroups = this.activeFundingGroups; this.getHistoricalCollectionsForSchool(); this.loadSchoolsFundingData(); diff --git a/frontend/src/components/institute/common/SchoolHistory.vue b/frontend/src/components/institute/common/SchoolHistory.vue index 77dd375ad..79574299b 100644 --- a/frontend/src/components/institute/common/SchoolHistory.vue +++ b/frontend/src/components/institute/common/SchoolHistory.vue @@ -156,7 +156,7 @@ export default { }, }, async beforeMount() { - await appStore().getCodes(); + await appStore().getInstituteCodes(); }, mounted() { this.getSchoolHistory(); diff --git a/frontend/src/components/institute/common/SchoolMove.vue b/frontend/src/components/institute/common/SchoolMove.vue index 4fa0b17d6..c637bfa90 100644 --- a/frontend/src/components/institute/common/SchoolMove.vue +++ b/frontend/src/components/institute/common/SchoolMove.vue @@ -141,7 +141,7 @@ export default { }, }, created() { - appStore().getCodes().then(() => this.getSchoolDetails()); + appStore().getInstituteCodes().then(() => this.getSchoolDetails()); }, methods: { hasRequiredPermission, diff --git a/frontend/src/components/nominal-roll/NomRollStudentSearchResults.vue b/frontend/src/components/nominal-roll/NomRollStudentSearchResults.vue index 117760fec..ada5f8ee0 100644 --- a/frontend/src/components/nominal-roll/NomRollStudentSearchResults.vue +++ b/frontend/src/components/nominal-roll/NomRollStudentSearchResults.vue @@ -495,7 +495,7 @@ export default { if (!this.gradeCodeObjects || !this.genders) { await studentStore().getCodes(); } - await appStore().getCodes(); + await appStore().getInstituteCodes(); }, computed: { ...mapState(nominalRollStudentSearchStore, ['nomRollStudentSearchResponse', 'nomRollStudentSearchCriteria', 'currentNomRollStudentSearchParams']), diff --git a/frontend/src/components/penreg/penrequest-batch/PrbStudentSearchResults.vue b/frontend/src/components/penreg/penrequest-batch/PrbStudentSearchResults.vue index 7ced0fe6c..571993fba 100644 --- a/frontend/src/components/penreg/penrequest-batch/PrbStudentSearchResults.vue +++ b/frontend/src/components/penreg/penrequest-batch/PrbStudentSearchResults.vue @@ -238,7 +238,7 @@ export default { }; }, async beforeMount() { - await appStore().getCodes(); + await appStore().getInstituteCodes(); }, computed: { ...mapState(penRequestBatchStudentSearchStore, ['prbStudentSearchResponse', 'prbStudentSearchCriteria', 'currentPrbStudentSearchParams']), diff --git a/frontend/src/components/penreg/student-registration/StudentRegistrationContactsDisplay.vue b/frontend/src/components/penreg/student-registration/StudentRegistrationContactsDisplay.vue index 381915f32..23e945695 100644 --- a/frontend/src/components/penreg/student-registration/StudentRegistrationContactsDisplay.vue +++ b/frontend/src/components/penreg/student-registration/StudentRegistrationContactsDisplay.vue @@ -92,7 +92,7 @@ export default { }; }, created() { - appStore().getCodes(); + appStore().getInstituteCodes(); }, mounted() { this.loadPenCoords(); diff --git a/frontend/src/components/penreg/student/StudentAuditHistoryDetailCard.vue b/frontend/src/components/penreg/student/StudentAuditHistoryDetailCard.vue index 649e032da..b4781df41 100644 --- a/frontend/src/components/penreg/student/StudentAuditHistoryDetailCard.vue +++ b/frontend/src/components/penreg/student/StudentAuditHistoryDetailCard.vue @@ -301,7 +301,7 @@ export default { }; }, async beforeMount() { - await appStore().getCodes(); + await appStore().getInstituteCodes(); }, computed: { ...mapState(studentStore, ['demogCodeObjects', 'statusCodeObjects', 'gradeCodeObjects','documentTypeCodes']), diff --git a/frontend/src/components/secure-message/AccessSchoolUsersPage.vue b/frontend/src/components/secure-message/AccessSchoolUsersPage.vue index 8403045b1..db0d93c6e 100644 --- a/frontend/src/components/secure-message/AccessSchoolUsersPage.vue +++ b/frontend/src/components/secure-message/AccessSchoolUsersPage.vue @@ -333,7 +333,7 @@ export default { await edxStore().getSchoolExchangeRoles(); } if (this.schoolMap.size === 0) { - await appStore().getCodes(); + await appStore().getInstituteCodes(); } }, created() { diff --git a/frontend/src/components/secure-message/ExchangePage.vue b/frontend/src/components/secure-message/ExchangePage.vue index 06dbf6a5f..48867748a 100644 --- a/frontend/src/components/secure-message/ExchangePage.vue +++ b/frontend/src/components/secure-message/ExchangePage.vue @@ -648,7 +648,7 @@ export default { } }, created() { - appStore().getCodes(); + appStore().getInstituteCodes(); edxStore().getCodes(); edxStore().getMinistryTeams().then(() => { this.getExchanges(); diff --git a/frontend/src/mixins/getSecureExchangeContactMixin.js b/frontend/src/mixins/getSecureExchangeContactMixin.js index 8c8e0cdd8..0335aa91e 100644 --- a/frontend/src/mixins/getSecureExchangeContactMixin.js +++ b/frontend/src/mixins/getSecureExchangeContactMixin.js @@ -6,7 +6,7 @@ import {appStore} from '@/store/modules/app'; export default { mounted() { - appStore().getCodes(); + appStore().getInstituteCodes(); edxStore().getCodes(); }, computed: { diff --git a/frontend/src/store/modules/app.js b/frontend/src/store/modules/app.js index 847f81173..4641b106f 100644 --- a/frontend/src/store/modules/app.js +++ b/frontend/src/store/modules/app.js @@ -119,36 +119,25 @@ export const appStore = defineStore('app', { this.collectionTypeCodesMap.set(element.collectionTypeCode, element) }) }, - async getCodes() { - if(localStorage.getItem('jwtToken')) { // DONT Call api if there is not token. - if(this.mincodeSchoolNames.size === 0) { - const response = await ApiService.getAllSchools(); - await this.setMincodeSchoolNameAndDistrictCodes(response.data); - } - if (this.activeSchools.length === 0) { - const response = await ApiService.getActiveSchools(); - await this.setActiveSchools(response.data); - } - if(this.districtMap.size === 0) { - const response = await ApiService.getDistricts(); - await this.setDistricts(response.data); - } - if (this.activeDistricts.length === 0) { - const response = await ApiService.getActiveDistricts(); - await this.setActiveDistricts(response.data); - } - if(this.independentAuthorityMap.size === 0) { - const response = await ApiService.getAuthorities(); - await this.setIndependentAuthorities(response.data); - } - if(this.fundingGroupsMap.size === 0 && !this.config.DISABLE_SDC_FUNCTIONALITY) { - const response = await ApiService.getAllFundingGroups(); - await this.setFundingGroups(response.data); - } - if(this.collectionTypeCodesMap.size === 0 && !this.config.DISABLE_SDC_FUNCTIONALITY) { - const response = await ApiService.getAllCollectionTypeCodes(); - await this.setCollectionTypeCodes(response.data); - } + async getInstituteCodes() { + if(localStorage.getItem('jwtToken')) {// DONT Call api if there is not token. + const promises = [ + ... this.mincodeSchoolNames.size === 0 ? [ApiService.getAllSchools().then((res) => this.setMincodeSchoolNameAndDistrictCodes(res.data))] : [], + ... this.activeSchools.length === 0 ? [ApiService.getActiveSchools().then((res) => this.setActiveSchools(res.data))] : [], + ... this.districtMap.size === 0 ? [ApiService.getDistricts().then((res) => this.setDistricts(res.data))] : [], + ... this.activeDistricts.length === 0 ? [ApiService.getActiveDistricts().then((res) => this.setActiveDistricts(res.data))] : [], + ... this.independentAuthorityMap.size === 0 ? [ApiService.getAuthorities().then((res) => this.setIndependentAuthorities(res.data))] : [] + ] + return Promise.all(promises) + } + }, + async getSdcCodes(){ + if(localStorage.getItem('jwtToken')){ + const promises = [ + ... this.fundingGroupsMap.size === 0 ? [ApiService.getAllFundingGroups().then((res)=> this.setFundingGroups(res.data))] : [], + ... this.collectionTypeCodesMap.size === 0 ? [ApiService.getAllCollectionTypeCodes().then((res) => this.setCollectionTypeCodes(res.data))]: [] + ]; + return Promise.all(promises) } }, async getConfig() {