Skip to content

Commit

Permalink
Merge pull request #2077 from bcgov/feature/penReview
Browse files Browse the repository at this point in the history
UI: Issue NEW PEN
  • Loading branch information
eckermania authored Oct 15, 2024
2 parents af2e020 + 0f86ccf commit 390ebf4
Show file tree
Hide file tree
Showing 4 changed files with 420 additions and 28 deletions.
12 changes: 10 additions & 2 deletions backend/src/components/sdc/sdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,12 +565,20 @@ async function updateStudentPEN(req, res) {
payload.updateUser = utils.getUser(req).idir_username;
payload.enrolledProgramCodes = null;
payload.penMatchResult = null;

if (payload?.numberOfCourses) {
payload.numberOfCourses = stripNumberFormattingNumberOfCourses(payload.numberOfCourses);
}
const data = await postData(`${config.get('sdc:schoolCollectionStudentURL')}/update-pen/type/${req.params.penCode}`, payload);
return res.status(HttpStatus.OK).json(data);
} catch (e) {
logApiError(e, 'Error updating student PEN');
return errorResponse(res);
if (e.status === 400 && e.data.message === 'SdcSchoolCollectionStudent was not saved to the database because it would create a provincial duplicate.') {
return res.status(HttpStatus.CONFLICT).json({
status: HttpStatus.CONFLICT,
message: 'Student was not saved because it would create provincial a duplicate.'
});
}
return handleExceptionResponse(e, res);
}
}

Expand Down
53 changes: 27 additions & 26 deletions frontend/src/components/data-collection/PenMatchStudentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
:loading="isIssuingNewPen"
:disabled="studentDetails?.penMatchResult === 'NEW' || studentDetails?.penMatchResult === 'MATCH'"
text="Issue new PEN"
@click-action="issueNewPen"
@click-action="togglePENRequestDialog"
/>
</v-row>
<v-row
Expand Down Expand Up @@ -150,6 +150,16 @@
</v-col>
</v-row>
</v-container>
<v-dialog
v-model="showPenRequestDialog"
:max-width="600"
>
<SDCIssueNewPEN
:sdc-student="clonedStudentDetail"
@cancel="togglePENRequestDialog"
@save-new-pen="saveNewPen"
/>
</v-dialog>
</template>
<script>
Expand All @@ -167,14 +177,17 @@ import PenMatchResults from './PenMatchResults.vue';
import {sdcCollectionStore} from '@/store/modules/sdcCollection';
import PrimaryButton from '../util/PrimaryButton.vue';
import _ from 'lodash';
import SDCIssueNewPEN from './SDCIssueNewPEN.vue';
import {constructPenMatchObjectFromSdcStudent} from '../../utils/common';
export default {
name: 'PenMatchStudentDetails',
components: {
Spinner,
StudentDetailsPanel,
PenMatchResults,
PrimaryButton
PrimaryButton,
SDCIssueNewPEN
},
mixins: [alertMixin],
async beforeRouteUpdate(to, from) {
Expand Down Expand Up @@ -210,6 +223,7 @@ export default {
'MATCH' : '#2E8540',
'NEW' : '#2E8540',
},
showPenRequestDialog: false,
};
},
beforeUnmount() {
Expand All @@ -234,6 +248,9 @@ export default {
},
methods: {
...mapActions(sdcCollectionStore, ['setSelectedIDs', 'setNavigationPage']),
togglePENRequestDialog(){
this.showPenRequestDialog = !this.showPenRequestDialog;
},
backButtonClick() {
this.$router.push({name: 'collection-view', query: {penMatch: true}, params: {collectionID: this.activeCollection?.collectionID}});
},
Expand Down Expand Up @@ -281,7 +298,7 @@ export default {
this.showPossibleMatch = false;
this.possibleMatches = [];
try {
const result = await getPossibleMatches(this.constructPenMatchObjectFromStudent());
const result = await getPossibleMatches(constructPenMatchObjectFromSdcStudent(this.studentDetails));
this.isIssuePenDisabled = false;
this.possibleMatches = result.data ?? [];
await this.checkForDuplicates();
Expand Down Expand Up @@ -331,53 +348,37 @@ export default {
this.getSdcSchoolCollectionStudentDetail(this.$route.params.studentID);
});
},
async issueNewPen() {
async saveNewPen(newPenDetails) {
this.isIssuingNewPen = true;
this.clonedStudentDetail.assignedPen = null;
this.clonedStudentDetail.assignedStudentId = null;
this.clonedStudentDetail.assignedPen = newPenDetails.assignedPen;
this.clonedStudentDetail.assignedStudentId = newPenDetails.assignedstudentId;
this.updatePEN('NEW').finally(() => {
this.isIssuingNewPen = false;
this.togglePENRequestDialog();
this.getSdcSchoolCollectionStudentDetail(this.$route.params.studentID);
});
},
async updatePEN(type) {
return ApiService.apiAxios.post(`${Routes.sdc.SDC_SCHOOL_COLLECTION_STUDENT}/${this.clonedStudentDetail.sdcSchoolCollectionStudentID}/update-pen/${type}`, this.clonedStudentDetail)
.then(() => {
if(type === 'NEW') {
this.setSuccessAlert('Your request to issue new PEN is accepted.');
this.setSuccessAlert('PEN updated successfully.');
} else {
this.setSuccessAlert('PEN has been MATCHED successfully');
this.setSuccessAlert('PEN has been MATCHED successfully.');
}
if(!this.nextDisabled) {
this.clickNextBtn();
}
})
.catch(error => {
this.setFailureAlert('An error occurred while updating PEN. Please try again later.');
this.setFailureAlert(error?.response?.data?.message ? error?.response?.data?.message : 'An error occurred while updating PEN. Please try again later.');
console.log(error);
});
},
clickOpenSearch(){
this.modifySearchDialog = true;
},
constructPenMatchObjectFromStudent() {
return {
pen: this.studentDetails.studentPen,
localID: this.studentDetails.localID,
surname: this.studentDetails.legalLastName,
givenName: this.studentDetails.legalFirstName,
middleName: this.studentDetails.legalMiddleNames,
usualSurname: this.studentDetails.usualLastName,
usualGiven: this.studentDetails.usualFirstName,
usualMiddleName: this.studentDetails.usualMiddleNames,
dob: this.studentDetails.dob,
sex: this.studentDetails.gender,
enrolledGradeCode: this.studentDetails.enrolledGradeCode,
mincode: '00807005',
postal: this.studentDetails.postalCode
};
},
async modifySearchParams(updatedStudent) {
if(updatedStudent) {
if(!_.isEqual(this.studentDetails, updatedStudent)) {
Expand Down
Loading

0 comments on commit 390ebf4

Please sign in to comment.