diff --git a/backend/src/components/institute/institute.js b/backend/src/components/institute/institute.js index 76c65b3e2..590a9d531 100644 --- a/backend/src/components/institute/institute.js +++ b/backend/src/components/institute/institute.js @@ -1,13 +1,15 @@ 'use strict'; -const { logApiError, getData, errorResponse, getBackendToken, validateAccessToken} = require('../utils'); +const { logApiError, getData, errorResponse, getBackendToken, validateAccessToken, getCodeTable} = require('../utils'); const HttpStatus = require('http-status-codes'); const cacheService = require('../cache-service'); -const {FILTER_OPERATION, VALUE_TYPE, CONDITION} = require('../../util/constants'); +const {FILTER_OPERATION, VALUE_TYPE, CONDITION, CACHE_KEYS} = require('../../util/constants'); const config = require('../../config'); const {LocalDateTime, LocalDate, DateTimeFormatter} = require('@js-joda/core'); const utils = require('../utils'); const _ = require('lodash'); const {isDistrictActive, isSchoolOrAuthorityClosedOrNeverOpened} = require('./instituteUtils'); +const lodash = require("lodash"); +const schoolApiCacheService = require("../school-api-cache-service"); async function getCachedDistricts(req, res) { try { @@ -863,6 +865,49 @@ async function getSchoolByID(req, res) { } } +async function getStudentRegistrationContacts(req, res) { + const token = getBackendToken(req); + let contactsList = []; + try { + const schoolContactURL = `${config.get('server:institute:instituteSchoolURL')}/contact/paginated?pageNumber=0&pageSize=10000&searchCriteriaList=[{"searchCriteriaList":[{"key":"schoolContactTypeCode","operation":"eq","value":"STUDREGIS","valueType":"STRING","condition":"AND"}]}]`; + const districtContactURL = `${config.get('server:institute:instituteDistrictURL')}/contact/paginated?pageNumber=0&pageSize=10000&searchCriteriaList=[{"searchCriteriaList":[{"key":"districtContactTypeCode","operation":"eq","value":"STUDREGIS","valueType":"STRING","condition":"AND"}]}]`; + Promise.all([ + getData(token, schoolContactURL), + getData(token, districtContactURL), + ]) + .then(async ([schoolContactResponse, districtContactResponse]) => { + if (schoolContactResponse && districtContactResponse) { + schoolContactResponse.content.forEach((element) => { + let school = cacheService.getSchoolBySchoolID(element.schoolId); + let schoolRegistrationContact = {}; + schoolRegistrationContact.name = (element.firstName ? element.firstName + ' ' + element.lastName : element.lastName).trim(); + schoolRegistrationContact.email = element.email; + schoolRegistrationContact.instituteName = school.schoolName; + schoolRegistrationContact.instituteIdentifier = school.mincode; + schoolRegistrationContact.instituteGUID = school.schoolID; + schoolRegistrationContact.instituteType = 'SCHOOL'; + contactsList.push(schoolRegistrationContact); + }); + districtContactResponse.content.forEach((element) => { + let district = cacheService.getDistrictJSONByDistrictId(element.districtId); + let schoolRegistrationContact = {}; + schoolRegistrationContact.name = (element.firstName ? element.firstName + ' ' + element.lastName : element.lastName).trim(); + schoolRegistrationContact.email = element.email; + schoolRegistrationContact.instituteName = district.name; + schoolRegistrationContact.instituteGUID = district.districtId; + schoolRegistrationContact.instituteIdentifier = district.districtNumber; + schoolRegistrationContact.instituteType = 'DISTRICT'; + contactsList.push(schoolRegistrationContact); + }); + return res.status(200).json(contactsList); + } + }); + } catch (e) { + logApiError(e, 'getStudentRegistrationContacts', 'Error occurred while attempting to GET student registration contacts.'); + return errorResponse(res); + } +} + async function updateSchool(req, res) { try { const token = getBackendToken(req); @@ -1347,5 +1392,6 @@ module.exports = { addDistrictContact, deleteDistrictContact, getSchoolHistoryPaginated, - moveSchool + moveSchool, + getStudentRegistrationContacts }; diff --git a/backend/src/components/school.js b/backend/src/components/school.js index dbd738936..a21efd908 100644 --- a/backend/src/components/school.js +++ b/backend/src/components/school.js @@ -63,32 +63,6 @@ async function updatePenCoordinatorByMincode(req, res) { } -async function getPenCoordinators(req, res) { - const token = getBackendToken(req); - try { - const url = `${config.get('server:schoolAPIURL')}/schools/pen-coordinator`; - const data = await getData(token, url); - const coords = lodash.sortBy(data, ['mincode', 'penCoordinatorName']); - const filteredCords = coords.filter(coord=> { - const school = schoolApiCacheService.getSchoolNameJSONByMincode(coord.mincode); - if(!school){ - return true; - } - return isSchoolExpired(school); - }).map(coord=> { - coord.schoolName = schoolApiCacheService.getSchoolNameJSONByMincode(coord.mincode)?.schoolName; - if(!coord.schoolName){ - coord.schoolName = 'District'; - } - return coord; - }); - return res.status(200).json(filteredCords); - } catch (e) { - logApiError(e, 'getPenCoordinators', 'Error occurred while attempting to GET pen coordinator entities.'); - return errorResponse(res); - } -} - function isSchoolExpired(school) { if(school === null){ return false; @@ -102,6 +76,5 @@ function isSchoolExpired(school) { module.exports = { getSchoolByMincode, getPenCoordinatorByMincode, - updatePenCoordinatorByMincode, - getPenCoordinators, + updatePenCoordinatorByMincode }; diff --git a/backend/src/routes/institute.js b/backend/src/routes/institute.js index 8aa97946e..52259cfd0 100644 --- a/backend/src/routes/institute.js +++ b/backend/src/routes/institute.js @@ -4,7 +4,8 @@ const router = express.Router(); const { getDistricts, getSchools, getSchoolsPaginated, getAuthoritiesPaginated, getAuthorityByID, getSchoolByID, getDistrictByDistrictID, addNewSchoolNote, updateSchoolNote, deleteSchoolNote, updateSchoolContact, updateAuthority, addAuthorityContact, updateAuthorityContact, deleteAuthorityContact, addNewAuthorityNote, updateAuthorityNote, deleteAuthorityNote, updateSchool, addSchool, addSchoolContact, deleteSchoolContact, updateDistrict, updateDistrictContact, deleteDistrictContact, addAuthority, - addDistrictContact, addNewDistrictNote, updateDistrictNote, deleteDistrictNote, moveSchool, getSchoolHistoryPaginated + addDistrictContact, addNewDistrictNote, updateDistrictNote, deleteDistrictNote, moveSchool, getSchoolHistoryPaginated, + getStudentRegistrationContacts } = require('../components/institute/institute'); const utils = require('../components/utils'); const auth = require('../components/auth'); @@ -18,6 +19,8 @@ router.get('/district/:districtId', passport.authenticate('jwt', {session: false router.put('/district/:districtId', passport.authenticate('jwt', {session: false}, undefined), auth.isValidDistrictAdmin, extendSession, updateDistrict); +router.get('/studentRegistrationContacts', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getStudentRegistrationContacts); + router.put('/district/contact/:contactId', passport.authenticate('jwt', {session: false}, undefined), auth.isValidDistrictAdmin, extendSession, updateDistrictContact); router.delete('/district/contact/:districtId/:contactId', passport.authenticate('jwt', {session: false}, undefined), auth.isValidDistrictAdmin, extendSession, deleteDistrictContact); diff --git a/backend/src/routes/schools.js b/backend/src/routes/schools.js index 1daeb1737..14e38d1ad 100644 --- a/backend/src/routes/schools.js +++ b/backend/src/routes/schools.js @@ -1,14 +1,9 @@ const passport = require('passport'); const express = require('express'); const router = express.Router(); -const { getSchoolByMincode, getPenCoordinatorByMincode, getPenCoordinators, updatePenCoordinatorByMincode } = require('../components/school'); +const { getSchoolByMincode, getPenCoordinatorByMincode } = require('../components/school'); const utils = require('../components/utils'); -const auth = require('../components/auth'); const extendSession = utils.extendSession(); -const roles = require('../components/roles'); - -const isValidUiTokenWithEditRoles = auth.isValidUiTokenWithRoles('StaffAdministration & NominalRoll', [roles.Admin.StaffAdministration, roles.Admin.NominalRoll, roles.Admin.EDX]); - /* * Get a school entity by mincode */ @@ -19,16 +14,6 @@ router.get('/', passport.authenticate('jwt', {session: false}, undefined), exten */ router.get('/:mincode/penCoordinator', passport.authenticate('jwt', {session: false}, undefined), extendSession, getPenCoordinatorByMincode); -/* - * Update a pen coordinator entity by mincode - */ -router.put('/:mincode/penCoordinator', passport.authenticate('jwt', {session: false}, undefined), isValidUiTokenWithEditRoles, extendSession, updatePenCoordinatorByMincode); - -/* - * Get all pen coordinator entities - */ -router.get('/penCoordinators', passport.authenticate('jwt', {session: false}, undefined), extendSession, getPenCoordinators); - router.get('/fedProvSchoolCodes', passport.authenticate('jwt', {session: false}, undefined), extendSession, utils.getCodes('server:schoolAPIURL', 'fedProvSchoolCodes', '/schools/federal-province-codes', false)); module.exports = router; diff --git a/frontend/src/components/institute/authority/AuthorityContact.vue b/frontend/src/components/institute/authority/AuthorityContact.vue index f0f5c3972..34ed86237 100644 --- a/frontend/src/components/institute/authority/AuthorityContact.vue +++ b/frontend/src/components/institute/authority/AuthorityContact.vue @@ -70,7 +70,7 @@ class="pt-1" >