Skip to content

Commit

Permalink
Updates for removing school API.
Browse files Browse the repository at this point in the history
  • Loading branch information
arcshiftsolutions committed Oct 20, 2023
1 parent 67ef6d1 commit 7dc85c3
Show file tree
Hide file tree
Showing 11 changed files with 11,988 additions and 8,655 deletions.
20,329 changes: 11,911 additions & 8,418 deletions backend/package-lock.json

Large diffs are not rendered by default.

66 changes: 61 additions & 5 deletions backend/src/components/institute/institute.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict';
const { logApiError, getData, errorResponse, getBackendToken, validateAccessToken, getCodeTable} = require('../utils');
const { logApiError, getData, errorResponse, getBackendToken, validateAccessToken} = require('../utils');
const HttpStatus = require('http-status-codes');
const cacheService = require('../cache-service');
const {FILTER_OPERATION, VALUE_TYPE, CONDITION, CACHE_KEYS} = require('../../util/constants');
const {FILTER_OPERATION, VALUE_TYPE, CONDITION} = 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 {
Expand Down Expand Up @@ -865,6 +863,20 @@ 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 = [];
Expand Down Expand Up @@ -908,6 +920,48 @@ async function getStudentRegistrationContacts(req, 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 && 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 @@ -1393,5 +1447,7 @@ module.exports = {
deleteDistrictContact,
getSchoolHistoryPaginated,
moveSchool,
getStudentRegistrationContacts
getStudentRegistrationContacts,
getStudentRegistrationContactByMincode,
getSchoolByMincode
};
48 changes: 0 additions & 48 deletions backend/src/components/school-api-cache-service.js

This file was deleted.

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

This file was deleted.

8 changes: 7 additions & 1 deletion backend/src/routes/institute.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ 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,
getStudentRegistrationContacts
getStudentRegistrationContacts,
getStudentRegistrationContactByMincode
} = 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);
Expand All @@ -21,6 +23,8 @@ router.put('/district/:districtId', passport.authenticate('jwt', {session: false

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 @@ -59,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/:id', passport.authenticate('jwt', {session: false}, undefined), auth.isLoggedInUser, extendSession, getSchoolByID);

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
10 changes: 0 additions & 10 deletions backend/src/routes/schools.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
const passport = require('passport');
const express = require('express');
const router = express.Router();
const { getSchoolByMincode, getPenCoordinatorByMincode } = require('../components/school');
const utils = require('../components/utils');
const extendSession = utils.extendSession();
/*
* 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);

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
60 changes: 0 additions & 60 deletions backend/tests/unit/components/school.spec.js

This file was deleted.

Loading

0 comments on commit 7dc85c3

Please sign in to comment.