Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing school API callouts in favor of institute #1600

Merged
merged 9 commits into from
Oct 20, 2023
104 changes: 103 additions & 1 deletion backend/src/components/institute/institute.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,105 @@ async function getSchoolByID(req, res) {
}
}

async function getSchoolByMincode(req, res) {
const token = getBackendToken(req);
try {
let school = cacheService.getSchoolJSONByMincode(req.params.mincode);
const url = `${config.get('server:institute:rootURL')}/school/${school.schoolID}`;
const data = await getData(token, url);
return res.status(200).json(data);
} catch (e) {
logApiError(e, 'getSchoolByMincode', 'Error occurred while attempting to GET school entity by mincode.');
return errorResponse(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 getStudentRegistrationContactByMincode(req, res) {
const accessToken = getBackendToken(req);
try {
let school = cacheService.getSchoolJSONByMincode(req.params.mincode);
let searchCriteriaList = [];
searchCriteriaList.push({key: 'schoolContactTypeCode', operation: FILTER_OPERATION.EQUAL, value: 'STUDREGIS', valueType: VALUE_TYPE.STRING, condition: CONDITION.AND});
searchCriteriaList.push({key: 'schoolID', operation: FILTER_OPERATION.EQUAL, value: school.schoolID, valueType: VALUE_TYPE.UUID, condition: CONDITION.AND});

const schoolSearchCriteria = [{
condition: null,
searchCriteriaList: searchCriteriaList,
}];

const schoolSearchParam = {
params: {
pageNumber: req.query.pageNumber,
pageSize: req.query.pageSize,
sort: req.query.sort,
searchCriteriaList: JSON.stringify(schoolSearchCriteria)
}
};

let response = await getData(accessToken, config.get('server:institute:rootURL') + '/school/contact/paginated', schoolSearchParam);
let schoolRegistrationContact = {};
if(response?.content && response.content[0]){
let firstStudRegContact = response.content[0];
schoolRegistrationContact.name = (firstStudRegContact.firstName ? firstStudRegContact.firstName + ' ' + firstStudRegContact.lastName : firstStudRegContact.lastName).trim();
schoolRegistrationContact.email = firstStudRegContact.email;
schoolRegistrationContact.instituteName = school.schoolName;
schoolRegistrationContact.instituteIdentifier = school.mincode;
schoolRegistrationContact.instituteGUID = school.schoolID;
schoolRegistrationContact.instituteType = 'SCHOOL';
}

return res.status(200).json(schoolRegistrationContact);
} catch (e) {
logApiError(e, 'getStudentRegistrationContactByMincode', 'Error occurred while attempting to GET student registration contact entity.');
return errorResponse(res);
}
}


async function updateSchool(req, res) {
try {
const token = getBackendToken(req);
Expand Down Expand Up @@ -1356,5 +1455,8 @@ module.exports = {
addDistrictContact,
deleteDistrictContact,
getSchoolHistoryPaginated,
moveSchool
moveSchool,
getStudentRegistrationContacts,
getStudentRegistrationContactByMincode,
getSchoolByMincode
};
48 changes: 0 additions & 48 deletions backend/src/components/school-api-cache-service.js

This file was deleted.

107 changes: 0 additions & 107 deletions backend/src/components/school.js

This file was deleted.

11 changes: 10 additions & 1 deletion backend/src/routes/institute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@ 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,
getStudentRegistrationContactByMincode, getSchoolByMincode
} = require('../components/institute/institute');
const utils = require('../components/utils');
const auth = require('../components/auth');
const extendSession = utils.extendSession();
const {getCodes} = require('../components/utils');
const {CACHE_KEYS} = require('../util/constants');


router.get('/district', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getDistricts);

router.get('/district/:districtId', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getDistrictByDistrictID);

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.get('/studentRegistrationContact/:mincode', passport.authenticate('jwt', {session: false}, undefined), extendSession, getStudentRegistrationContactByMincode);

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 Expand Up @@ -56,6 +63,8 @@ router.post('/school/contact', passport.authenticate('jwt', {session: false}, un

router.get('/school/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getSchoolByID);

router.get('/school/mincode/:mincode', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getSchoolByMincode);

router.put('/school/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, updateSchool);

router.get('/schoolsPaginated', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getSchoolsPaginated);
Expand Down
25 changes: 0 additions & 25 deletions backend/src/routes/schools.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
const passport = require('passport');
const express = require('express');
const router = express.Router();
const { getSchoolByMincode, getPenCoordinatorByMincode, getPenCoordinators, updatePenCoordinatorByMincode } = 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
*/
router.get('/', passport.authenticate('jwt', {session: false}, undefined), extendSession, getSchoolByMincode);

/*
* Get a pen coordinator entity by mincode
*/
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));

Expand Down
20 changes: 0 additions & 20 deletions backend/src/schedulers/school-api-cache-service-scheduler.js

This file was deleted.

6 changes: 0 additions & 6 deletions backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const server = http.createServer(app);
const WS = require('./socket/web-socket');
const NATS = require('./messaging/message-pub-sub');
const cacheService = require('./components/cache-service');
const schoolApiCacheServicce = require('./components/school-api-cache-service');
const constants = require('./util/constants');

cacheService.loadAllSchoolsToMap().then(() => {
Expand Down Expand Up @@ -125,11 +124,6 @@ cacheService.loadAllDocumentTypeCodesToMap().then(() => {
}).catch((e) => {
log.error('Error loading document type codes during boot .', e);
});
schoolApiCacheServicce.loadAllSchoolsToMap().then(() => {
log.info('Loaded school data to memory school-api-cache');
}).catch((e) => {
log.error('Error loading schools during boot school-api-cache .', e);
});
WS.init(app, server);

/**
Expand Down
Loading
Loading