Skip to content

Commit

Permalink
Merge pull request #1990 from bcgov/fix/dupes
Browse files Browse the repository at this point in the history
Dupes cleanup
  • Loading branch information
arcshiftsolutions authored Nov 12, 2024
2 parents a753278 + 7b6e3f9 commit 1ac8467
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 256 deletions.
8 changes: 0 additions & 8 deletions backend/src/components/cache-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ let authoritiesMap = new Map();
let bandCodesMap = new Map();
let enrolledProgramCodesMap = new Map();
let careerProgramCodesMap = new Map();
let duplicateResolutionCodesMap = new Map();
let programDuplicateTypeCodesMap = new Map();
let schoolFundingCodesMap = new Map();
let schoolCollectionStatusCodesMap = new Map();
Expand Down Expand Up @@ -280,13 +279,6 @@ const cacheService = {
});
return homeLanguageSpokenCodesMap;
},
getAllDuplicateResolutionCodesMap() {
let duplicateResolutionCodes = cachedData[constants.CACHE_KEYS.SDC_DUPLICATE_RESOLUTION_CODES].records;
duplicateResolutionCodes.forEach(duplicateResolutionCode => {
duplicateResolutionCodesMap.set(duplicateResolutionCode.duplicateResolutionCode, duplicateResolutionCode);
});
return duplicateResolutionCodesMap;
},
getAllProgramDuplicateTypeCodesMap() {
let programDuplicateTypeCodes = cachedData[constants.CACHE_KEYS.SDC_PROGRAM_DUPLICATE_TYPE_CODES].records;
programDuplicateTypeCodes.forEach(programDuplicateTypeCode => {
Expand Down
10 changes: 2 additions & 8 deletions backend/src/components/permissionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,8 @@ async function checkSdcDuplicateAccess(req, res, next) {
message: 'Token is unavailable.'
});
}
res.locals.sdcDuplicate = await getData(token, `${config.get('sdc:sdcDuplicateURL')}/${req.body.duplicate.sdcDuplicateID}`, req.session?.correlationID);
if(req.body.duplicate?.updateDate !== res.locals.sdcDuplicate?.updateDate){
return res.status(HttpStatus.CONFLICT).json({
status: HttpStatus.CONFLICT,
message: 'The duplicate you are attempting to update is already being saved by another user. Please refresh your screen and try again.'
});
}
let sdcDupStudents = [res.locals.sdcDuplicate?.sdcSchoolCollectionStudent1Entity, res.locals.sdcDuplicate?.sdcSchoolCollectionStudent2Entity];

let sdcDupStudents = [req?.body?.duplicate?.sdcSchoolCollectionStudent1Entity, req?.body?.duplicate?.sdcSchoolCollectionStudent2Entity];
res.locals.sdcSchoolCollectionStudentsToUpdate = sdcDupStudents?.filter(dupStudent => req.body.students?.map(student => student.sdcSchoolCollectionStudentID)?.includes(dupStudent.sdcSchoolCollectionStudentID));
if(res.locals.sdcSchoolCollectionStudentsToUpdate?.length !== req.body.students?.length) {
return res.status(HttpStatus.FORBIDDEN).json({
Expand Down
43 changes: 5 additions & 38 deletions backend/src/components/sdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,12 +838,9 @@ function setDuplicateResponsePayload(req, sdcDuplicates, isProvincialDuplicate,
const result = {
enrollmentDuplicates: {
NON_ALLOW: [],
ALLOWABLE: [],
RESOLVED: []
},
programDuplicates: {
NON_ALLOW: [],
RESOLVED: []
}
};
sdcDuplicates?.forEach(sdcDuplicate => {
Expand All @@ -855,18 +852,12 @@ function setDuplicateResponsePayload(req, sdcDuplicates, isProvincialDuplicate,
toTableRow(sdcDuplicate.sdcSchoolCollectionStudent1Entity);
toTableRow(sdcDuplicate.sdcSchoolCollectionStudent2Entity);

if (sdcDuplicate?.duplicateTypeCode === DUPLICATE_TYPE_CODES.ENROLLMENT && sdcDuplicate.duplicateResolutionCode) {
setStudentResolvedMessage(sdcDuplicate);
result.enrollmentDuplicates.RESOLVED.push(sdcDuplicate);
}
else if (sdcDuplicate?.duplicateTypeCode === DUPLICATE_TYPE_CODES.ENROLLMENT) {
if (sdcDuplicate?.duplicateTypeCode === DUPLICATE_TYPE_CODES.ENROLLMENT) {
setIfOnlineStudentAndCanChangeGrade(sdcDuplicate, school1, school2);
setCanMoveToCrossEnrollment(sdcDuplicate);
result.enrollmentDuplicates[sdcDuplicate.duplicateSeverityCode].push(sdcDuplicate);
}
else if (sdcDuplicate?.duplicateTypeCode === DUPLICATE_TYPE_CODES.PROGRAM && sdcDuplicate.duplicateResolutionCode) {
setProgramDuplicateTypeMessage(sdcDuplicate);
result.programDuplicates.RESOLVED.push(sdcDuplicate);
if(sdcDuplicate.duplicateSeverityCode === 'NON_ALLOW') {
result.enrollmentDuplicates[sdcDuplicate.duplicateSeverityCode].push(sdcDuplicate);
}
}
else if (sdcDuplicate?.duplicateTypeCode === DUPLICATE_TYPE_CODES.PROGRAM) {
setProgramDuplicateTypeMessage(sdcDuplicate);
Expand Down Expand Up @@ -996,29 +987,6 @@ function getSchoolName(school) {
return school.mincode + ' - ' + school.schoolName;
}

function setStudentResolvedMessage(sdcDuplicate) {
if(!sdcDuplicate.duplicateResolutionCode) {
return;
}
const resolutionCodes = cacheService.getAllDuplicateResolutionCodesMap();
const resolutionMessage = resolutionCodes.get(sdcDuplicate.duplicateResolutionCode)?.message;
const retainedId = sdcDuplicate.retainedSdcSchoolCollectionStudentEntity?.sdcSchoolCollectionStudentID;
if (sdcDuplicate.sdcSchoolCollectionStudent1Entity.sdcSchoolCollectionStudentID === retainedId) {
if(sdcDuplicate.duplicateResolutionCode === 'GRADE_CHNG'){
sdcDuplicate.sdcSchoolCollectionStudent1Entity.resolution = resolutionMessage;
} else {
sdcDuplicate.sdcSchoolCollectionStudent2Entity.resolution = resolutionMessage;
}
}
else if (sdcDuplicate.sdcSchoolCollectionStudent2Entity.sdcSchoolCollectionStudentID === retainedId) {
if(sdcDuplicate.duplicateResolutionCode === 'GRADE_CHNG'){
sdcDuplicate.sdcSchoolCollectionStudent2Entity.resolution = resolutionMessage;
} else {
sdcDuplicate.sdcSchoolCollectionStudent1Entity.resolution = resolutionMessage;
}
}
}

function setIfOnlineStudentAndCanChangeGrade(sdcDuplicate, school1, school2) {
if(['DIST_LEARN', 'DISTONLINE'].includes(school1.facilityTypeCode) && ['08', '09'].includes(sdcDuplicate.sdcSchoolCollectionStudent1Entity.enrolledGradeCode)) {
sdcDuplicate.sdcSchoolCollectionStudent1Entity.canChangeGrade = true;
Expand Down Expand Up @@ -1091,8 +1059,7 @@ async function resolveDuplicates(req, res) {
try {
const token = getAccessToken(req);


let duplicateLock = await redisUtil.lockSdcDuplicateBeingProcessedInRedis(res.locals.sdcDuplicate.sdcDuplicateID);
let duplicateLock = await redisUtil.lockSdcDuplicateBeingProcessedInRedis(res.locals.sdcSchoolCollectionStudentsToUpdate.sdcSchoolCollectionStudentID);
const payload = req.body.students;
payload.forEach(student => {
student.createDate = null;
Expand Down
1 change: 0 additions & 1 deletion backend/src/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ nconf.defaults({
validationIssueTypeCodesURL: process.env.SDC_API_ENDPOINT + '/validation-issue-type-codes',
programEligibilityTypeCodesURL: process.env.SDC_API_ENDPOINT + '/program-eligibility-issue-codes',
zeroFteReasonCodesURL: process.env.SDC_API_ENDPOINT + '/zero-fte-reason-codes',
duplicateResolutionCodesURL: process.env.SDC_API_ENDPOINT + '/duplicate-resolution-codes',
programDuplicateTypeCodesURL: process.env.SDC_API_ENDPOINT + '/program-duplicate-type-codes',
schoolCollectionStatusCodesURL: process.env.SDC_API_ENDPOINT + '/school-collection-status-codes',
sdcDuplicateURL: process.env.SDC_API_ENDPOINT + '/sdc-duplicate',
Expand Down
13 changes: 9 additions & 4 deletions backend/src/routes/sdc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions backend/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ if(process.env.NODE_ENV !== 'test'){ //do not cache for test environment to sto
}).catch((e) => {
log.error('Error loading SDC_SPECIAL_ED_CODES data during boot.', e);
});
cacheService.loadDataToCache(constants.CACHE_KEYS.SDC_DUPLICATE_RESOLUTION_CODES, 'sdc:duplicateResolutionCodesURL').then(() => {
log.info('Loaded SDC_DUPLICATE_RESOLUTION_CODES data to memory');
}).catch((e) => {
log.error('Error loading SDC_DUPLICATE_RESOLUTION_CODES data during boot.', e);
});
cacheService.loadDataToCache(constants.CACHE_KEYS.SDC_PROGRAM_DUPLICATE_TYPE_CODES, 'sdc:programDuplicateTypeCodesURL').then(() => {
log.info('Loaded SDC_PROGRAM_DUPLICATE_TYPE_CODES data to memory');
}).catch((e) => {
Expand Down
1 change: 0 additions & 1 deletion backend/src/util/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ cacheKeys = {
SDC_VALIDATION_ISSUE_TYPE_CODES: 'sdc_validation_issue_type_codes',
SDC_PROGRAM_ELIGIBILITY_TYPE_CODES: 'sdc_program_eligibility_type_codes',
SDC_ZERO_FTE_REASON_CODES: 'sdc_zero_fte_reason_codes',
SDC_DUPLICATE_RESOLUTION_CODES: 'sdc_duplicate_resolution_codes',
SDC_PROGRAM_DUPLICATE_TYPE_CODES: 'sdc_program_duplicate_type_codes',
PRB_VALIDATION_ISSUE_TYPE_CODES: 'prb_validation_issue_type_codes',
COLLECTION_TYPE_CODES: 'collection_type_codes',
Expand Down
1 change: 0 additions & 1 deletion backend/src/validations/sdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ const postResolveDuplicateSchema = object({
duplicate: object() //Marked as object to support dynamic naming
}).concat(baseRequestSchema),
params: object({
sdcDuplicateID: string().nonNullable(),
type: string().nonNullable()
}),
query: object(),
Expand Down
1 change: 0 additions & 1 deletion frontend/src/common/apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export default {
getAllValidationIssueTypeCodes:getCodes(`${ApiRoutes.sdc.SDC_VALIDATION_ISSUE_TYPE_CODES}`),
getAllProgramEligibilityTypeCodes:getCodes(`${ApiRoutes.sdc.SDC_PROGRAM_ELIGIBILITY_TYPE_CODES}`),
getAllZeroFteReasonCodes:getCodes(`${ApiRoutes.sdc.SDC_ZERO_FTE_REASON_CODES}`),
getAllDuplicateResolutionCodes:getCodes(`${ApiRoutes.sdc.SDC_DUPLICATE_RESOLUTION_CODES}`),
getAllSchoolCollectionStatusCodes:getCodes(`${ApiRoutes.sdc.SDC_SCHOOL_COLLECTION_STATUS_CODES}`),
getAllActiveBandCodes:getCodes(`${ApiRoutes.sdc.SDC_BAND_CODES}?active=true`),
getPRBValidationIssueTypeCodes:getCodes(`${ApiRoutes.penServices.PRB_VALIDATION_ISSUE_TYPE_CODE_URL}`),
Expand Down
Loading

0 comments on commit 1ac8467

Please sign in to comment.