Skip to content

Commit

Permalink
Update registration - staff side
Browse files Browse the repository at this point in the history
  • Loading branch information
sumathi-thirumani committed Nov 27, 2024
1 parent f4c7709 commit 9f905e1
Show file tree
Hide file tree
Showing 18 changed files with 973 additions and 152 deletions.
8 changes: 6 additions & 2 deletions backend/src/components/cache-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ const cacheService = {
if (assessmentTypeCodesResponse && assessmentTypeCodesResponse.length > 0) {
assessmentTypeCodesMap.clear(); // reset the value.
assessmentTypeCodesResponse.forEach(entry => {
assessmentTypeCodesMap.set(entry.assessmentTypeCode, entry.label);
assessmentTypeCodesMap.set(entry.assessmentTypeCode, {'label': entry.label, 'displayOrder': entry.displayOrder });
});
}
log.info(`Loaded ${assessmentTypeCodesMap.size} assessmentTypeCodes.`);
Expand All @@ -265,14 +265,18 @@ const cacheService = {
});
},

getAssessmentTypeLabelByCode(assessmentTypeCode) {
getAssessmentTypeByCode(assessmentTypeCode) {
return assessmentTypeCodesMap.get(assessmentTypeCode);
},

getSpecialCaseTypeLabelByCode(specialCaseTypeCode) {
return assessmentSpecialCaseTypeCodesMap.get(specialCaseTypeCode);
},

getAllAssessmentSpecialCases(){
return assessmentSpecialCaseTypeCodesMap;
},

async loadDataToCache(cacheKey,url){
log.debug(` loading all ${cacheKey} during start up`);
await retry(async () => {
Expand Down
108 changes: 83 additions & 25 deletions backend/src/components/eas/eas.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ async function getAssessmentSessionsBySchoolYear(req, res) {
const url = `${config.get('server:eas:assessmentSessionsURL')}/school-year/${req.params.schoolYear}`;
let data = await getData(url);
data.forEach(session => {
session.isOpen = new Date(session.activeFromDate) <= new Date() && new Date(session.activeUntilDate) >= new Date();
session.assessments.forEach(assessment => {
assessment.assessmentTypeName = cacheService.getAssessmentTypeLabelByCode(assessment.assessmentTypeCode)+' ('+assessment.assessmentTypeCode+')';
let assessmentType = cacheService.getAssessmentTypeByCode(assessment.assessmentTypeCode);
assessment.assessmentTypeName = assessmentType.label+' ('+assessment.assessmentTypeCode+')';
assessment.displayOrder = assessmentType.displayOrder;
});
});
return res.status(200).json(data);
Expand Down Expand Up @@ -59,17 +62,15 @@ async function updateAssessmentSession(req, res) {
}
}

async function getAssessmentStudentsPaginated(req, res) {
async function getAssessmentStudentsPaginated(req, res) {
try {
const search = [];

const search = [];
if (req.query.searchParams?.['moreFilters']) {
let criteriaArray = createMoreFiltersSearchCriteria(req.query.searchParams['moreFilters']);
criteriaArray.forEach(criteria => {
search.push(criteria);
});
}

const params = {
params: {
pageNumber: req.query.pageNumber,
Expand All @@ -78,30 +79,13 @@ async function getAssessmentStudentsPaginated(req, res) {
searchCriteriaList: JSON.stringify(search),
}
};

let data = await getData(`${config.get('server:eas:assessmentStudentsURL')}/paginated`, params);

let data = await getData(`${config.get('server:eas:assessmentStudentsURL')}/paginated`, params);
if (req?.query?.returnKey) {
let result = data?.content.map((student) => student[req?.query?.returnKey]);
return res.status(HttpStatus.OK).json(result);
}
data?.content.forEach(value => {
let school = cacheService.getSchoolBySchoolID(value.schoolID);
let assessmentCenter = cacheService.getSchoolBySchoolID(value.assessmentCenterID);
let district = cacheService.getDistrictJSONByDistrictId(school.districtID);

value.schoolNumber = school.mincode;
value.schoolName = getSchoolName(school);
value.districtID = school.districtID;
value.districtNumber = district.districtNumber;
value.districtName = getDistrictName(district);
value.assessmentCenterNumber = assessmentCenter.mincode;
value.assessmentCenterName = getSchoolName(assessmentCenter);

value.assessmentTypeName = cacheService.getAssessmentTypeLabelByCode(value.assessmentTypeCode)+' ('+value.assessmentTypeCode+')';
value.provincialSpecialCaseName = cacheService.getSpecialCaseTypeLabelByCode(value.provincialSpecialCaseCode);
value.sessionName = moment(value.courseMonth, 'MM').format('MMMM') +' '+value.courseYear;

includeAssessmentStudentProps(value);
});
return res.status(200).json(data);
} catch (e) {
Expand All @@ -114,6 +98,66 @@ async function getAssessmentStudentsPaginated(req, res) {
}
}

async function getAssessmentStudentByID(req, res) {
try {

let data = await getData(`${config.get('server:eas:assessmentStudentsURL')}/${req.params.assessmentStudentID}`);
return res.status(200).json(includeAssessmentStudentProps(data));
} catch (e) {
if (e?.status === 404) {
res.status(HttpStatus.OK).json(null);
} else {
await logApiError(e, 'Error getting eas assessment student');
return errorResponse(res);
}
}
}

async function updateAssessmentStudentByID(req, res) {
if (req.params.assessmentStudentID !== req.body.assessmentStudentID) {
return res.status(HttpStatus.BAD_REQUEST).json({
message: 'The assessmentStudentID in the URL didn\'t match the assessmentStudentID in the request body.'
});
}
try {
const userInfo = utils.getUser(req);
const payload = {
...req.body,
updateUser: userInfo.idir_username,
updateDate: null,
createDate: null
};
const result = await utils.putData(`${config.get('server:eas:assessmentStudentsURL')}/${req.params.assessmentStudentID}`, payload, utils.getUser(req).idir_username);
return res.status(HttpStatus.OK).json(result);
} catch (e) {
logApiError(e, 'updateAssessmentStudent', 'Error occurred while attempting to save the changes to the assessment student registration.');
return errorResponse(res);
}
}

function includeAssessmentStudentProps(assessmentStudent) {
if(assessmentStudent) {
let school = cacheService.getSchoolBySchoolID(assessmentStudent.schoolID);
let assessmentCenter = assessmentStudent.assessmentCenterID ? cacheService.getSchoolBySchoolID(assessmentStudent.assessmentCenterID) : null;
let district = cacheService.getDistrictJSONByDistrictId(school.districtID);

if(school && district) {
assessmentStudent.schoolName_desc = getSchoolName(school);
assessmentStudent.districtID = school.districtID;
assessmentStudent.districtName_desc = getDistrictName(district);
}

if(assessmentCenter) {
assessmentStudent.assessmentCenterName_desc = getSchoolName(assessmentCenter);
}

assessmentStudent.assessmentTypeName_desc = cacheService.getAssessmentTypeByCode(assessmentStudent.assessmentTypeCode).label+' ('+assessmentStudent.assessmentTypeCode+')';
assessmentStudent.provincialSpecialCaseName_desc = assessmentStudent.provincialSpecialCaseCode ? cacheService.getSpecialCaseTypeLabelByCode(assessmentStudent.provincialSpecialCaseCode) : null;
assessmentStudent.sessionName_desc = moment(assessmentStudent.courseMonth, 'MM').format('MMMM') +' '+assessmentStudent.courseYear;
}
return assessmentStudent;
}

function getSchoolName(school) {
return school.mincode + ' - ' + school.schoolName;
}
Expand All @@ -122,9 +166,23 @@ function getDistrictName(district) {
return district.districtNumber + ' - ' + district.name;
}

function getAssessmentSpecialCases(req, res) {
try {
const codes = cacheService.getAllAssessmentSpecialCases();
return res.status(HttpStatus.OK).json(Object.fromEntries(codes));
} catch (e) {
logApiError(e, 'getAssessmentSpecialCases', 'Error occurred while attempting to get specialcase types.');
return errorResponse(res);
}
}


module.exports = {
getAssessmentSessions,
getAssessmentSessionsBySchoolYear,
updateAssessmentSession,
getAssessmentStudentsPaginated
getAssessmentStudentsPaginated,
getAssessmentStudentByID,
updateAssessmentStudentByID,
getAssessmentSpecialCases
};
51 changes: 3 additions & 48 deletions backend/src/components/eas/studentFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,15 @@ function createMoreFiltersSearchCriteria(searchFilter = []) {
}

if (key === 'districtNameNumber' && pValue) {
let districtNameNumberCriteria = createDistrictNameNumberSearchCriteria(pValue.toString());
districtNameNumberFilter = [...districtNameNumberCriteria];
searchCriteriaList.push({ key: 'districtID', value: pValue.toString(), operation: FILTER_OPERATION.EQUAL, valueType: VALUE_TYPE.UUID, condition: CONDITION.AND });
}

if (key === 'schoolNameNumber' && pValue) {
let schoolNameNumberCriteria = createSchoolNameNumberSearchCriteria(pValue.toString());
schoolNameNumberFilter = [...schoolNameNumberCriteria];
searchCriteriaList.push({ key: 'schoolID', value: pValue.toString(), operation: FILTER_OPERATION.EQUAL, valueType: VALUE_TYPE.UUID, condition: CONDITION.AND });
}

if (key === 'assessmentCenterNameNumber' && pValue) {
let schoolNameNumberCriteria = createAssessmentCenterNameNumberSearchCriteria(pValue.toString());
assessmentCenterNameNumberFilter = [...schoolNameNumberCriteria];
searchCriteriaList.push({ key: 'assessmentCenterID', value: pValue.toString(), operation: FILTER_OPERATION.EQUAL, valueType: VALUE_TYPE.UUID, condition: CONDITION.AND });
}

if (key === 'session' && pValue) {
Expand Down Expand Up @@ -101,48 +98,6 @@ function createMoreFiltersSearchCriteria(searchFilter = []) {
return search;
}

function createDistrictNameNumberSearchCriteria(value) {
const searchDistrictCriteriaList = [];

searchDistrictCriteriaList.push({
key: 'districtID',
operation: FILTER_OPERATION.EQUAL,
value: value,
valueType: VALUE_TYPE.UUID,
condition: CONDITION.AND
});

return searchDistrictCriteriaList;
}

function createSchoolNameNumberSearchCriteria(value) {
const searchSchoolCriteriaList = [];

searchSchoolCriteriaList.push({
key: 'schoolID',
operation: FILTER_OPERATION.EQUAL,
value: value,
valueType: VALUE_TYPE.UUID,
condition: CONDITION.AND
});

return searchSchoolCriteriaList;
}

function createAssessmentCenterNameNumberSearchCriteria(value) {
const searchAssessmentCenterCriteriaList = [];

searchAssessmentCenterCriteriaList.push({
key: 'assessmentCenterID',
operation: FILTER_OPERATION.EQUAL,
value: value,
valueType: VALUE_TYPE.UUID,
condition: CONDITION.AND
});

return searchAssessmentCenterCriteriaList;
}


module.exports = {
createMoreFiltersSearchCriteria
Expand Down
7 changes: 6 additions & 1 deletion backend/src/routes/eas.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const passport = require('passport');
const express = require('express');
const router = express.Router();
const { getAssessmentSessions, getAssessmentSessionsBySchoolYear, updateAssessmentSession, getAssessmentStudentsPaginated } = require('../components/eas/eas');
const { getAssessmentSessions, getAssessmentSessionsBySchoolYear, updateAssessmentSession, getAssessmentStudentsPaginated, getAssessmentStudentByID, updateAssessmentStudentByID, getAssessmentSpecialCases } = require('../components/eas/eas');
const utils = require('../components/utils');
const extendSession = utils.extendSession();
const permUtils = require('../components/permissionUtils');
const perm = require('../util/Permission');
const validate = require('../components/validator');
const {putStudentAssessmentSchema} = require('../validations/eas');

const PERMISSION = perm.PERMISSION;

Expand All @@ -14,7 +16,10 @@ router.get('/assessment-sessions', passport.authenticate('jwt', {session: false}
router.get('/assessment-sessions/school-year/:schoolYear', passport.authenticate('jwt', {session: false}, undefined), permUtils.checkUserHasPermission(PERMISSION.MANAGE_EAS_SESSIONS_PERMISSION), extendSession, getAssessmentSessionsBySchoolYear);
router.put('/assessment-sessions/:sessionID', passport.authenticate('jwt', {session: false}, undefined), permUtils.checkUserHasPermission(PERMISSION.MANAGE_EAS_SESSIONS_PERMISSION), extendSession, updateAssessmentSession);

router.get('/assessment-registrations/student/:assessmentStudentID', passport.authenticate('jwt', {session: false}, undefined), permUtils.checkUserHasPermission(PERMISSION.VIEW_EAS_STUDENT_PERMISSION), extendSession, getAssessmentStudentByID);
router.put('/assessment-registrations/student/:assessmentStudentID', passport.authenticate('jwt', {session: false}, undefined), permUtils.checkUserHasPermission(PERMISSION.EDIT_EAS_STUDENT_PERMISSION), extendSession, validate(putStudentAssessmentSchema), updateAssessmentStudentByID);
router.get('/assessment-registrations/paginated', passport.authenticate('jwt', {session: false}, undefined), permUtils.checkUserHasPermission(PERMISSION.VIEW_EAS_STUDENT_PERMISSION), extendSession, getAssessmentStudentsPaginated);

router.get('/assessment-specialcase-types', passport.authenticate('jwt', {session: false}, undefined), permUtils.checkUserHasPermission(PERMISSION.MANAGE_EAS_SESSIONS_PERMISSION), extendSession, getAssessmentSpecialCases);

module.exports = router;
4 changes: 3 additions & 1 deletion backend/src/util/Permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const PERMISSION = Object.freeze(
REPORTS_SDC_INDEPENDENT_SCHOOLS_PERMISSION: 'REPORTS_SDC_INDEPENDENT_SCHOOLS_PERMISSION',
REPORTS_SDC_HEADCOUNTS_PERMISSION: 'REPORTS_SDC_HEADCOUNTS_PERMISSION',
MANAGE_EAS_SESSIONS_PERMISSION:'MANAGE_EAS_SESSIONS_PERMISSION',
VIEW_EAS_STUDENT_PERMISSION: 'VIEW_EAS_STUDENT_PERMISSION'
VIEW_EAS_STUDENT_PERMISSION: 'VIEW_EAS_STUDENT_PERMISSION',
EDIT_EAS_STUDENT_PERMISSION: 'EDIT_EAS_STUDENT_PERMISSION'

}
);

Expand Down
12 changes: 12 additions & 0 deletions backend/src/validations/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { object, string, date } = require('yup');

const baseRequestSchema = object({
createDate: date().nullable().optional(),
createUser: string().nullable().max(100).optional(),
updateDate: date().nullable().optional(),
updateUser: string().nullable().max(100).optional(),
}).noUnknown();

module.exports = {
baseRequestSchema,
};
34 changes: 34 additions & 0 deletions backend/src/validations/eas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const { object, string, boolean, number } = require('yup');
const { baseRequestSchema } = require('./base');

const putStudentAssessmentSchema = object({
body: object({
assessmentStudentID: string().nonNullable(),
sessionID:string().nonNullable(),
districtID: string().nonNullable(),
schoolID: string().nonNullable(),
assessmentCenterID: string().nullable().optional(),
assessmentID:string().nonNullable(),
assessmentTypeCode: string().nonNullable(),
studentID: string().nonNullable(),
pen: string().max(9).nonNullable(),
localID: string().max(12).nonNullable(),
givenName: string().max(25).nonNullable(),
surName: string().max(25).nonNullable(),
isElectronicExam: boolean().nonNullable(),
proficiencyScore: number().nullable().optional(),
provincialSpecialCaseCode: string().max(1).nullable().optional(),
courseStatusCode: string().max(1).nullable().optional(),
numberOfAttempts: number().nullable().optional(),
courseMonth: number().optional(),
courseYear: number().optional(),
}).concat(baseRequestSchema).noUnknown(),
params: object({
studentAssessmentID: string().nonNullable(),
}),
query: object().noUnknown(),
}).noUnknown();

module.exports = {
putStudentAssessmentSchema,
};
3 changes: 3 additions & 0 deletions frontend/src/common/apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ export default {
getAllActiveHomeLanguageSpokenCodes:getCodes(`${Routes.sdc.SDC_HOME_LANGUAGE_SPOKEN_CODES}?active=true`),
getAllActiveSchoolFundingCodes:getCodes(`${Routes.sdc.SDC_SCHOOL_FUNDING_CODES}?active=true`),
getAllActiveSpecialEdCodes:getCodes(`${Routes.sdc.SDC_SPECIAL_ED_CODES}?active=true`),

getAllEASSpecialCaseCodes:getCodes(`${Routes.eas.GET_ASSESSMENT_SPECIALCASE_TYPES}`),

async getConfig() {
try {
const response = await apiAxios.get(Routes.CONFIG);
Expand Down
Loading

0 comments on commit 9f905e1

Please sign in to comment.