diff --git a/services/backend/src/services/populations/getStudentData.ts b/services/backend/src/services/populations/getStudentData.ts index 43db5a1ed..d26e38210 100644 --- a/services/backend/src/services/populations/getStudentData.ts +++ b/services/backend/src/services/populations/getStudentData.ts @@ -1,6 +1,6 @@ import { Op } from 'sequelize' -import { Credit, Enrollment, SISStudyRight, SISStudyRightElement, Student, Studyplan } from '@oodikone/shared/models' +import { SISStudyRight, SISStudyRightElement, Student, Studyplan } from '@oodikone/shared/models' import { Tag, TagStudent } from '@oodikone/shared/models/kone' import { EnrollmentState } from '@oodikone/shared/types' import { enrollmentTimeDateThreshold } from '@oodikone/shared/util' @@ -14,6 +14,7 @@ import { SISStudyRightElementModel, } from '../../models' import { TagModel, TagStudentModel } from '../../models/kone' +import { StudentCredit, StudentEnrollment } from '@oodikone/shared/types/studentData' export type StudentTags = TagStudent & { tag: Pick @@ -46,17 +47,21 @@ export const getStudentTagMap = async (studyRights: string[], studentNumbers: st return studentTagMap } -export type StudentEnrollment = Pick< - Enrollment, - 'course_id' | 'state' | 'enrollment_date_time' | 'semestercode' | 'studentnumber' | 'studyright_id' -> export const getEnrollments = ( studentNumbers: string[], startDate: string, endDate: string ): Promise => EnrollmentModel.findAll({ - attributes: ['course_id', 'state', 'enrollment_date_time', 'semestercode', 'studentnumber', 'studyright_id'], + attributes: [ + 'course_id', + 'course_code', + 'state', + 'enrollment_date_time', + 'semestercode', + 'studentnumber', + 'studyright_id', + ], where: { studentnumber: { [Op.in]: studentNumbers, @@ -185,19 +190,6 @@ export const getStudents = (studentNumbers: string[]): Promise data.map(x => x.get({ plain: true }))) -export type StudentCredit = Pick< - Credit, - | 'grade' - | 'credits' - | 'credittypecode' - | 'attainment_date' - | 'isStudyModule' - | 'student_studentnumber' - | 'course_id' - | 'language' - | 'studyright_id' -> - export const getCredits = async ( studentNumbers: string[], startDate: string, @@ -213,6 +205,7 @@ export const getCredits = async ( 'isStudyModule', 'student_studentnumber', 'course_id', + 'course_code', 'language', 'studyright_id', ], diff --git a/services/backend/src/services/populations/statisticsOf.ts b/services/backend/src/services/populations/statisticsOf.ts index 576770a43..e3b25a63f 100644 --- a/services/backend/src/services/populations/statisticsOf.ts +++ b/services/backend/src/services/populations/statisticsOf.ts @@ -4,8 +4,6 @@ import { getCriteria } from '../studyProgramme/studyProgrammeCriteria' import { getCourseDetails } from '../courses' import { formatStudentForAPI } from './formatStatisticsForApi' import { - type StudentEnrollment, - type StudentCredit, type StudentTags, getStudents, getEnrollments, @@ -13,6 +11,7 @@ import { getStudyRightElementsForStudyRight, } from './getStudentData' import { getCourseGroupIds, getOptionsForStudents } from './shared' +import { StudentCredit, StudentEnrollment } from '@oodikone/shared/types/studentData' export type OptimizedStatisticsQuery = { userId: string diff --git a/services/frontend/src/components/CustomPopulation/CustomPopulationContent.tsx b/services/frontend/src/components/CustomPopulation/CustomPopulationContent.tsx index aa9c45869..c51047dac 100644 --- a/services/frontend/src/components/CustomPopulation/CustomPopulationContent.tsx +++ b/services/frontend/src/components/CustomPopulation/CustomPopulationContent.tsx @@ -55,7 +55,7 @@ export const CustomPopulationContent = ({ useEffect(() => { setStudentAmountLimit(Math.round(filteredStudents.length ? filteredStudents.length * 0.3 : 0)) - }, [filteredStudents.length]) + }, [filteredStudents.length, setStudentAmountLimit]) const onStudentAmountLimitChange = value => { setStudentAmountLimit(Number.isNaN(Number(value)) ? studentAmountLimit : Number(value)) @@ -123,7 +123,7 @@ export const CustomPopulationContent = ({ showBachelorAndMaster: false, includePrimaryProgramme: false, - coursecodes: [], + courseIds: [], from: undefined, to: undefined, }) diff --git a/services/frontend/src/redux/populations/util.ts b/services/frontend/src/redux/populations/util.ts index 9c64a3cb8..9a1768c65 100644 --- a/services/frontend/src/redux/populations/util.ts +++ b/services/frontend/src/redux/populations/util.ts @@ -78,6 +78,7 @@ export const formatPopulationData = ( return { course_id: credit.course_id, + course_code: credit.course_code, date: credit.attainment_date, passed, grade: passed ? credit.grade : 'Hyl.', diff --git a/services/shared/routes/populations.ts b/services/shared/routes/populations.ts index 05057e544..246813063 100644 --- a/services/shared/routes/populations.ts +++ b/services/shared/routes/populations.ts @@ -1,4 +1,4 @@ -import { Credit, Enrollment, Course } from '../models' +import { Course } from '../models' import { Name, ProgrammeModuleWithRelevantAttributes, @@ -8,7 +8,7 @@ import { ProgressCriteria, Unification, } from '../types' -import { FormattedStudent } from '../types/studentData' +import { FormattedStudent, StudentCredit, StudentEnrollment } from '../types/studentData' export type CourseStats = Pick @@ -60,22 +60,8 @@ export type PopulationCourseStats = { // One row per groupId (isPrimary=true course for that group) courses: CourseStats[] idToGroupIdMap: Record - enrollments: Pick< - Enrollment, - 'course_id' | 'state' | 'enrollment_date_time' | 'semestercode' | 'studentnumber' | 'studyright_id' - >[] - credits: Pick< - Credit, - | 'grade' - | 'credits' - | 'credittypecode' - | 'attainment_date' - | 'isStudyModule' - | 'student_studentnumber' - | 'course_id' - | 'language' - | 'studyright_id' - >[] + enrollments: (StudentEnrollment & { studentnumber: string })[] + credits: StudentCredit[] } // populationstatistics diff --git a/services/shared/test/utils/formatted.ts b/services/shared/test/utils/formatted.ts index 3ec4b1029..4cb100311 100644 --- a/services/shared/test/utils/formatted.ts +++ b/services/shared/test/utils/formatted.ts @@ -70,6 +70,7 @@ export const createStudyRight = (overrides: Partial = {}): St export const createCourse = (overrides: Partial = {}): StudentCourse => ({ course_id: 'hy-CU-000000001-2024-08-01', + course_code: 'MAT001', date: new Date('2024-08-01'), passed: true, grade: '5', @@ -95,6 +96,7 @@ export const createEnrollment = ( overrides: Partial = {} ): FormattedStudent['enrollments'][number] => ({ course_id: 'hy-CU-000000001-2024-08-01', + course_code: 'MAT001', state: EnrollmentState.ENROLLED, enrollment_date_time: new Date('2024-08-01'), semestercode: 149, diff --git a/services/shared/types/studentData.ts b/services/shared/types/studentData.ts index 2246980a9..4a6f1b962 100644 --- a/services/shared/types/studentData.ts +++ b/services/shared/types/studentData.ts @@ -1,4 +1,4 @@ -import type { Enrollment, SISStudyRight, SISStudyRightElement, Student, Studyplan } from '../models' +import type { Credit, Enrollment, SISStudyRight, SISStudyRightElement, Student, Studyplan } from '../models' import type { Tag, TagStudent } from '../models/kone' import type { CriteriaYear, CreditTypeCode, Name, ProgrammeModule } from '../types' @@ -106,6 +106,7 @@ export type StudentPageStudent = { export type StudentCourse = { course_id: string + course_code: string date: Date passed: boolean grade: string @@ -116,6 +117,25 @@ export type StudentCourse = { studyright_id: string } +export type StudentCredit = Pick< + Credit, + | 'grade' + | 'credits' + | 'credittypecode' + | 'attainment_date' + | 'isStudyModule' + | 'student_studentnumber' + | 'course_id' + | 'course_code' + | 'language' + | 'studyright_id' +> + +export type StudentEnrollment = Pick< + Enrollment, + 'course_id' | 'course_code' | 'state' | 'enrollment_date_time' | 'semestercode' | 'studentnumber' | 'studyright_id' +> + export type FormattedStudent = { obfuscated?: true @@ -146,5 +166,5 @@ export type FormattedStudent = { studyRights: StudentStudyRight[] studyplans: StudentStudyPlan[] courses: StudentCourse[] - enrollments: Pick[] + enrollments: Omit[] }