From 9062d9a7262e419a5f028fe2e99b36ae41dc646e Mon Sep 17 00:00:00 2001 From: Eckerman Date: Thu, 9 Jan 2025 16:33:45 -0800 Subject: [PATCH] Adds validation issue handling to student reg edit --- backend/src/validations/eas.js | 12 +- .../forms/EditStudentRegistration.vue | 497 +++++++++--------- 2 files changed, 269 insertions(+), 240 deletions(-) diff --git a/backend/src/validations/eas.js b/backend/src/validations/eas.js index 429226c3..c70828a9 100644 --- a/backend/src/validations/eas.js +++ b/backend/src/validations/eas.js @@ -3,11 +3,11 @@ const { baseRequestSchema } = require('./base'); const putStudentAssessmentSchema = object({ body: object({ - assessmentStudentID: string().nullable().optional, + assessmentStudentID: string().nonNullable(), sessionID:string().nonNullable(), - districtID: string().nonNullable(), + districtID: string().nullable().optional(), schoolID: string().nonNullable(), - assessmentCenterID: string().nullable().optional(), + assessmentCenterID: string().nonNullable(), assessmentID:string().nonNullable(), assessmentTypeCode: string().nonNullable(), studentID: string().nonNullable(), @@ -15,17 +15,19 @@ const putStudentAssessmentSchema = object({ localID: string().max(12).nonNullable(), givenName: string().max(25).nonNullable(), surName: string().max(25).nonNullable(), - isElectronicExam: boolean().nonNullable(), + isElectronicExam: boolean().nullable().optional(), proficiencyScore: number().nullable().optional(), provincialSpecialCaseCode: string().max(1).nullable().optional(), courseStatusCode: string().max(1).nullable().optional(), - numberOfAttempts: number().nullable(), + numberOfAttempts: number().nullable().optional(), courseMonth: number().optional(), courseYear: number().optional(), assessmentStudentValidationIssues: array().of(object({ + assessmentStudentValidationIssueID:string().nullable().optional(), assessmentStudentID:string().nullable().optional(), validationIssueSeverityCode:string().nullable().optional(), validationIssueCode:string().nullable().optional(), + validationIssueFieldCode:string().nullable().optional(), validationLabel:string().nullable().optional(), validationMessage:string().nullable().optional(), }).concat(baseRequestSchema)).nullable().optional() diff --git a/frontend/src/components/assessments/registrations/forms/EditStudentRegistration.vue b/frontend/src/components/assessments/registrations/forms/EditStudentRegistration.vue index d1d911b2..3b06026e 100644 --- a/frontend/src/components/assessments/registrations/forms/EditStudentRegistration.vue +++ b/frontend/src/components/assessments/registrations/forms/EditStudentRegistration.vue @@ -4,228 +4,234 @@ -
- - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
+ - - - - - - - - - - - - - - - - - - - - - - - + style="margin-left: 1em" + align="start" + truncate-line="start" + > + + + +

+ {{ issue.validationLabel }} +

+
+
+ + + {{issue.validationMessage}} + + +
+
+
-
-
+ +
- @@ -255,6 +261,7 @@ import { mapState } from 'pinia'; import {easStore} from '../../../../store/modules/eas'; import moment from 'moment'; +import {PROFICIENCY_SCORE_RANGE_FILTER} from "../../../../utils/eas/StudentRegistrationTableConfiguration"; export default { name: 'EditStudentRegistration', @@ -297,12 +304,14 @@ export default { assessmentTypeSearchNames: [], assessmentCenterSearchNames: [], specialCaseSearchNames: [], + proficiencyScoreSearchNames: [], selectedAssessmentStudentID: null, studentRegistrationDetailsFormValid: false, assessmentStudentDetail: {}, loadingCount: 0, isActive: false, - isSessionEditable: false + isSessionEditable: false, + hasError: false }; }, computed: { @@ -359,7 +368,8 @@ export default { this.setupSpecialCaseCodes(); this.loading = false; }); - }); + }); + this.setupProficiencyScore(); }, methods: { isLoading(){ @@ -388,15 +398,28 @@ export default { }); this.sessionSearchNames = sortBy(this.sessionSearchNames, ['sessionCourseYear','sessionCourseMonth']); }, - setupSpecialCaseCodes() { + setupSpecialCaseCodes($event) { this.specialCaseSearchNames = []; + if($event && Number($event) >0 && this.assessmentStudentDetail.provincialSpecialCaseCode === 'A') { + return; + } Object.keys(this.specialCaseCodes).forEach(key => { - this.specialCaseSearchNames.push({ - specialCaseCodeName: this.specialCaseCodes[key], - specialCaseCodeValue: key + if(!(this.assessmentStudentDetail.proficiencyScore && key === 'A')) { + this.specialCaseSearchNames.push({ + specialCaseCodeName: this.specialCaseCodes[key], + specialCaseCodeValue: key + }); + } + }); + this.specialCaseSearchNames = sortBy(this.specialCaseSearchNames, ['specialCaseCodeName']); + }, + setupProficiencyScore() { + PROFICIENCY_SCORE_RANGE_FILTER.filterOptions.forEach(entry => { + this.proficiencyScoreSearchNames.push({ + proficiencyScoreCodeName: entry.id, + proficiencyScoreCodeValue: entry.value }); }); - this.specialCaseSearchNames = sortBy(this.specialCaseSearchNames, ['specialCaseCodeName']); }, refreshAssessmentTypes($event) { let session = this.schoolYearSessions.find(session => session.sessionID === $event); @@ -460,26 +483,30 @@ export default { Object.entries(this.assessmentStudentDetail).filter(([key]) => !key.endsWith('_desc')) ); ApiService.apiAxios - .put( - `${ApiRoutes.eas.ASSESSMENT_STUDENTS}/${this.userInfo.activeInstituteType}/`+this.selectedAssessmentStudentID, - putAssessmentStudentDetail - ) - .then(() => { - setSuccessAlert('Success! The student registration details have been updated.'); - this.$emit('reset-student-registration-pagination'); - }) - .catch((error) => { - console.error(error); - setFailureAlert( - error?.response?.data?.message - ? error?.response?.data?.message - : 'An error occurred while trying to update student registration details. Please try again later.' - ); - }) - .finally(() => { - this.loadingCount -= 1; - this.$emit('reset-student-registration-parent'); - }); + .put( + `${ApiRoutes.eas.ASSESSMENT_STUDENTS}/${this.userInfo.activeInstituteType}/`+this.selectedAssessmentStudentID, + putAssessmentStudentDetail + ) + .then((res) => { + this.assessmentStudentDetail.assessmentStudentValidationIssues = res.data.assessmentStudentValidationIssues; + if(this.assessmentStudentDetail.assessmentStudentValidationIssues){ + this.hasError = true; + } else if(!this.assessmentStudentDetail.assessmentStudentValidationIssues) { + this.hasError = false; + setSuccessAlert('Success! The student registration details have been updated.'); + this.$emit('reset-student-registration-pagination'); + this.$emit('reset-student-registration-parent'); + } + this.loadingCount -= 1; + }) + .catch((error) => { + console.error(error); + setFailureAlert( + error?.response?.data?.message + ? error?.response?.data?.message + : 'An error occurred while trying to update student registration details. Please try again later.' + ); + }) }, deleteStudentRegistration() { const confirmation = this.$refs.confirmRemoveStudentRegistration.open('Confirm Removal of Student Registration', null, {color: '#fff', width: 580, closeIcon: false, subtitle: false, dark: false, resolveText: 'Remove', rejectText: 'Cancel'});