Skip to content

Commit

Permalink
First part of updates for student regisration contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Oct 20, 2023
1 parent eae6643 commit 67ef6d1
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 438 deletions.
52 changes: 49 additions & 3 deletions backend/src/components/institute/institute.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';
const { logApiError, getData, errorResponse, getBackendToken, validateAccessToken} = require('../utils');
const { logApiError, getData, errorResponse, getBackendToken, validateAccessToken, getCodeTable} = require('../utils');

Check failure on line 2 in backend/src/components/institute/institute.js

View workflow job for this annotation

GitHub Actions / test

'getCodeTable' is assigned a value but never used
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');

Check failure on line 5 in backend/src/components/institute/institute.js

View workflow job for this annotation

GitHub Actions / test

'CACHE_KEYS' is assigned a value but never used
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");

Check failure on line 11 in backend/src/components/institute/institute.js

View workflow job for this annotation

GitHub Actions / test

'lodash' is assigned a value but never used
const schoolApiCacheService = require("../school-api-cache-service");

Check failure on line 12 in backend/src/components/institute/institute.js

View workflow job for this annotation

GitHub Actions / test

'schoolApiCacheService' is assigned a value but never used

async function getCachedDistricts(req, res) {
try {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1347,5 +1392,6 @@ module.exports = {
addDistrictContact,
deleteDistrictContact,
getSchoolHistoryPaginated,
moveSchool
moveSchool,
getStudentRegistrationContacts
};
29 changes: 1 addition & 28 deletions backend/src/components/school.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -102,6 +76,5 @@ function isSchoolExpired(school) {
module.exports = {
getSchoolByMincode,
getPenCoordinatorByMincode,
updatePenCoordinatorByMincode,
getPenCoordinators,
updatePenCoordinatorByMincode
};
5 changes: 4 additions & 1 deletion backend/src/routes/institute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
Expand Down
17 changes: 1 addition & 16 deletions backend/src/routes/schools.js
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
class="pt-1"
>
<p class="missing-highlight"><v-icon
size="x-large"
size="small"
color="#ff5252"
dark
>mdi-alert</v-icon> Missing contact details</p>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/institute/common/SchoolContact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
class="pt-1"
>
<p class="missing-highlight"><v-icon
size="x-large"
size="small"
color="#ff5252"
dark
>mdi-alert</v-icon> Missing contact details</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
class="pt-1"
>
<p class="missing-highlight"><v-icon
size="x-large"
size="small"
color="#ff5252"
dark
>mdi-alert</v-icon> Missing contact details</p>
Expand Down
Loading

0 comments on commit 67ef6d1

Please sign in to comment.