Skip to content

Commit

Permalink
Merge pull request #2109 from bcgov/feature/AddStudentRegistration
Browse files Browse the repository at this point in the history
Creating new assessment student registrations
  • Loading branch information
eckermania authored Dec 27, 2024
2 parents 6eb01a4 + 662e2e9 commit fbb9108
Show file tree
Hide file tree
Showing 11 changed files with 627 additions and 51 deletions.
44 changes: 38 additions & 6 deletions backend/src/components/eas/eas.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
'use strict';
const { logApiError, getAccessToken, getData, putData, deleteData, getCreateOrUpdateUserValue, getDataWithParams, handleExceptionResponse } = require('../utils');
const { logApiError, getAccessToken, getData, putData, postData, deleteData, getCreateOrUpdateUserValue, getDataWithParams, handleExceptionResponse} = require('../utils');
const HttpStatus = require('http-status-codes');
const config = require('../../config');
const cacheService = require('../cache-service');
const { createMoreFiltersSearchCriteria } = require('./studentFilters');
const moment = require('moment');
const {DateTimeFormatter, LocalDate, LocalDateTime} = require("@js-joda/core");

async function getAssessmentSessions(req, res) {
try {
const url = `${config.get('eas:assessmentSessionsURL')}`;
const token = getAccessToken(req);
const data = await getData(token, url);
const today = LocalDate.now();
const formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;

data.forEach(session => {
session.isOpen = new Date(session.activeFromDate) <= new Date() && new Date(session.activeUntilDate) >= new Date();
const activeFromDate = LocalDate.parse(session.activeFromDate, formatter);
const activeUntilDate = LocalDate.parse(session.activeUntilDate, formatter);
session.isOpen = activeFromDate.isBefore(today) && activeUntilDate.isAfter(today);
});

return res.status(200).json(data);
} catch (e) {
logApiError(e, 'getAssessmentSessions', 'Error occurred while attempting to GET assessment sessions.');
Expand All @@ -38,15 +45,21 @@ async function getAssessmentSessionsBySchoolYear(req, res) {
const url = `${config.get('eas:assessmentSessionsURL')}/school-year/${req.params.schoolYear}`;
const token = getAccessToken(req);
let data = await getData(token, url);

const now = LocalDateTime.now();

data.forEach(session => {
session.isOpen = new Date(session.activeFromDate) <= new Date() && new Date(session.activeUntilDate) >= new Date();
const activeFrom = LocalDateTime.parse(session.activeFromDate);
const activeUntil = LocalDateTime.parse(session.activeUntilDate);
session.isOpen = activeFrom.isBefore(now) && activeUntil.isAfter(now);

session.assessments.forEach(assessment => {
let assessmentType = cacheService.getAssessmentTypeByCode(assessment.assessmentTypeCode);
assessment.assessmentTypeName = assessmentType.label+' ('+assessment.assessmentTypeCode+')';
assessment.assessmentTypeName = assessmentType.label + ' (' + assessment.assessmentTypeCode + ')';
assessment.displayOrder = assessmentType.displayOrder;

});
});

return res.status(200).json(data);
} catch (e) {
logApiError(e, 'getSessions', 'Error occurred while attempting to GET sessions by school year.');
Expand Down Expand Up @@ -95,6 +108,24 @@ async function getAssessmentStudentsPaginated(req, res) {
}
}

async function postAssessmentStudent(req, res){
try {
req.body.districtID = cacheService.getSchoolBySchoolID(req.body.schoolID).districtID;
const payload = {
...req.body,
updateUser: getCreateOrUpdateUserValue(req),
updateDate: null,
createDate: null
};
const token = getAccessToken(req);
const result = await postData(token, payload, `${config.get('eas:assessmentStudentsURL')}`, req.session?.correlationID);
return res.status(HttpStatus.OK).json(result);
} catch (e) {
await logApiError(e, 'postAssessmentStudent', 'Error occurred while attempting to create the assessment student registration.');
return handleExceptionResponse(e, res);
}
}

async function getAssessmentStudentByID(req, res) {
try {
const token = getAccessToken(req);
Expand Down Expand Up @@ -190,5 +221,6 @@ module.exports = {
getAssessmentStudentByID,
updateAssessmentStudentByID,
deleteAssessmentStudentByID,
getAssessmentSpecialCases
getAssessmentSpecialCases,
postAssessmentStudent
};
5 changes: 3 additions & 2 deletions backend/src/routes/eas.js

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

41 changes: 38 additions & 3 deletions backend/src/validations/eas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { baseRequestSchema } = require('./base');

const putStudentAssessmentSchema = object({
body: object({
assessmentStudentID: string().nonNullable(),
assessmentStudentID: string().nullable().optional,
sessionID:string().nonNullable(),
districtID: string().nonNullable(),
schoolID: string().nonNullable(),
Expand All @@ -23,11 +23,11 @@ const putStudentAssessmentSchema = object({
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()
}).concat(baseRequestSchema).noUnknown(),
params: object({
Expand All @@ -36,6 +36,41 @@ const putStudentAssessmentSchema = object({
query: object().noUnknown(),
}).noUnknown();

const postAssessmentStudentSchema = object({
body: object({
sessionID:string().nonNullable(),
districtID: string().nonNullable(),
schoolID: string().nonNullable(),
assessmentCenterID: string().nonNullable(),
assessmentID:string().nonNullable(),
assessmentTypeCode: string().nonNullable(),
studentID: string().nullable().optional(),
assessmentStudentID: string().nullable().optional(),
courseStatusCode: string().nullable().optional(),
numberOfAttempts: string().nullable().optional(),
pen: string().max(9).nonNullable(),
localID: string().max(12).nonNullable(),
givenName: string().max(25).nonNullable(),
surName: string().max(25).nonNullable(),
isElectronicExam: boolean().nullable().optional(),
proficiencyScore: number().nullable().optional(),
provincialSpecialCaseCode: string().max(1).nullable().optional(),
assessmentStudentValidationIssues: array().of(object({
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()
}).concat(baseRequestSchema).noUnknown(),
query: object().noUnknown(),
params: object({
instituteType: string().nonNullable(),
}).noUnknown(),
}).noUnknown();

module.exports = {
putStudentAssessmentSchema,
postAssessmentStudentSchema
};
46 changes: 25 additions & 21 deletions frontend/src/components/assessments/AssessmentSessions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import { ApiRoutes } from '../../utils/constants';
import { authStore } from '../../store/modules/auth';
import { mapState } from 'pinia';
import moment from 'moment';
import { LocalDateTime } from "@js-joda/core";
export default {
name: 'AssessmentSessions',
Expand Down Expand Up @@ -147,18 +148,19 @@ export default {
};
},
computed: {
...mapState(authStore, ['userInfo']),
...mapState(authStore, ['userInfo']),
activeSessions() {
const orderedSessions = [];
const allSessions = this.allSessions
.filter(session => session.schoolYear === this.schoolYear)
.map((session) => {
return {
.filter(session => session.schoolYear === this.schoolYear)
.map(session => ({
...session,
courseMonth: this.formatMonth(session.courseMonth)
};
});
allSessions.sort((a, b) => new Date(a.activeUntilDate) - new Date(b.activeUntilDate));
}))
.sort((a, b) =>
LocalDateTime.parse(a.activeUntilDate).compareTo(LocalDateTime.parse(b.activeUntilDate))
);
for (let i = 0; i < allSessions.length; i += 2) {
orderedSessions.push(allSessions.slice(i, i + 2));
}
Expand All @@ -185,20 +187,22 @@ export default {
getAllAssessmentSessions() {
this.loading = true;
ApiService.apiAxios
.get(`${ApiRoutes.eas.GET_ASSESSMENT_SESSIONS}` + '/' + this.userInfo.activeInstituteType, {})
.then((response) => {
this.allSessions = response.data.sort((a, b) => new Date(b.activeUntilDate) - new Date(a.activeUntilDate));
if(this.allSessions.length >0) {
this.schoolYear = this.allSessions[0].schoolYear;
}
})
.catch((error) => {
console.error(error);
})
.finally(() => {
this.loading = false;
});
},
.get(`${ApiRoutes.eas.GET_ASSESSMENT_SESSIONS}` + '/' + this.userInfo.activeInstituteType, {})
.then((response) => {
this.allSessions = response.data.sort((a, b) =>
LocalDateTime.parse(b.activeUntilDate).compareTo(LocalDateTime.parse(a.activeUntilDate))
);
if (this.allSessions.length > 0) {
this.schoolYear = this.allSessions[0].schoolYear;
}
})
.catch((error) => {
console.error(error);
})
.finally(() => {
this.loading = false;
});
},
formattoDate(date) {
return moment(JSON.stringify(date), 'YYYY-MM-DDTHH:mm:ss').format('YYYY/MM/DD');
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
</span>
</v-col>
<v-col cols="8" class="d-flex justify-end">
<v-btn
id="addStudentReg"
color="#003366"
text="Add Record"
class="mr-1 mb-1"
variant="outlined"
@click="openCreateStudentRegDialog"
/>
<v-btn
id="filters"
color="#003366"
Expand Down Expand Up @@ -69,6 +77,21 @@
/>
</v-navigation-drawer>
</v-row>
<v-bottom-sheet
v-model="newStudentRegistrationSheet"
:inset="true"
:no-click-animation="true"
:persistent="true"
max-height="90vh"
>
<AddStudentRegistration
:session-id="sessionID"
:school-year-sessions="schoolYearSessions"
@reload-student-registrations="reloadStudentRegistrationsFlag = true"
@close-new-student-registration="closeNewAndLoadStudentRegistrations"
@update:sessionID="sessionID = $event"
/>
</v-bottom-sheet>
<v-bottom-sheet
v-model="editStudentRegistrationSheet"
:inset="true"
Expand Down Expand Up @@ -97,10 +120,12 @@ import {ApiRoutes} from '../../../utils/constants';
import {authStore} from '../../../store/modules/auth';
import {mapState} from 'pinia';
import StudentRegistrationDetail from './StudentRegistrationDetail.vue';
import AddStudentRegistration from "./forms/AddStudentRegistration.vue";
export default {
name: 'StudentRegistrations',
components: {
AddStudentRegistration,
StudentRegistrationsCustomTable,
StudentRegistrationsFilter,
StudentRegistrationDetail
Expand Down Expand Up @@ -137,6 +162,7 @@ export default {
canLoadPrevious: false,
resetFlag: false,
studentRegistrationForEdit: null,
newStudentRegistrationSheet: false,
reloadStudentRegistrationsFlag: false,
editStudentRegistrationSheet: false,
};
Expand Down Expand Up @@ -164,6 +190,16 @@ export default {
}
this.reloadStudentRegistrationsFlag = false;
},
closeNewAndLoadStudentRegistrations(){
this.newStudentRegistrationSheet = !this.newStudentRegistrationSheet;
if(this.reloadStudentRegistrationsFlag === true){
this.getAssessmentStudents();
}
this.reloadStudentRegistrationsFlag = false;
},
openCreateStudentRegDialog() {
this.newStudentRegistrationSheet = !this.newStudentRegistrationSheet;
},
selectTableConfig() {
this.config = this.userInfo.activeInstituteType === 'DISTRICT' ? SCHOOL_YEAR_REGISTRATIONS_VIEW_DISTRICT : SCHOOL_YEAR_REGISTRATIONS_VIEW_SCHOOL;
},
Expand Down
Loading

0 comments on commit fbb9108

Please sign in to comment.