diff --git a/services/backend/src/services/populations/getStudentData.ts b/services/backend/src/services/populations/getStudentData.ts index d26e38210..5b70c244a 100644 --- a/services/backend/src/services/populations/getStudentData.ts +++ b/services/backend/src/services/populations/getStudentData.ts @@ -1,4 +1,4 @@ -import { Op } from 'sequelize' +import { col, Op } from 'sequelize' import { SISStudyRight, SISStudyRightElement, Student, Studyplan } from '@oodikone/shared/models' import { Tag, TagStudent } from '@oodikone/shared/models/kone' @@ -12,6 +12,7 @@ import { StudyplanModel, SISStudyRightModel, SISStudyRightElementModel, + CourseModel, } from '../../models' import { TagModel, TagStudentModel } from '../../models/kone' import { StudentCredit, StudentEnrollment } from '@oodikone/shared/types/studentData' @@ -190,11 +191,7 @@ export const getStudents = (studentNumbers: string[]): Promise data.map(x => x.get({ plain: true }))) -export const getCredits = async ( - studentNumbers: string[], - startDate: string, - endDate: string -): Promise => +export const getCredits = async (studentNumbers: string[], startDate: string, endDate: string) => CreditModel.findAll({ raw: true, attributes: [ @@ -208,12 +205,19 @@ export const getCredits = async ( 'course_code', 'language', 'studyright_id', + [col('course.group_id'), 'courseGroupId'], ], + include: { + model: CourseModel, + attributes: [], + as: 'course', + required: true, + }, where: { student_studentnumber: { [Op.in]: studentNumbers }, attainment_date: { [Op.between]: [startDate, endDate] }, }, - }) + }) as unknown as Promise export const getStudyRightElementsForStudyRight = async (studentNumbers: string[], code: string) => SISStudyRightElementModel.findAll({ diff --git a/services/frontend/src/redux/populations/util.ts b/services/frontend/src/redux/populations/util.ts index 9853e82e6..4bf262c79 100644 --- a/services/frontend/src/redux/populations/util.ts +++ b/services/frontend/src/redux/populations/util.ts @@ -71,6 +71,7 @@ export const formatPopulationData = ( return { course_id: credit.course_id, course_code: credit.course_code, + courseGroupId: credit.courseGroupId, date: credit.attainment_date, passed, grade: passed ? credit.grade : 'Hyl.', diff --git a/services/shared/types/studentData.ts b/services/shared/types/studentData.ts index 4a6f1b962..0dc0cce6d 100644 --- a/services/shared/types/studentData.ts +++ b/services/shared/types/studentData.ts @@ -1,4 +1,4 @@ -import type { Credit, Enrollment, SISStudyRight, SISStudyRightElement, Student, Studyplan } from '../models' +import type { Course, Credit, Enrollment, SISStudyRight, SISStudyRightElement, Student, Studyplan } from '../models' import type { Tag, TagStudent } from '../models/kone' import type { CriteriaYear, CreditTypeCode, Name, ProgrammeModule } from '../types' @@ -115,6 +115,7 @@ export type StudentCourse = { credittypecode: CreditTypeCode language: string studyright_id: string + courseGroupId: Course['groupId'] } export type StudentCredit = Pick< @@ -129,7 +130,7 @@ export type StudentCredit = Pick< | 'course_code' | 'language' | 'studyright_id' -> +> & { courseGroupId: Course['groupId'] } export type StudentEnrollment = Pick< Enrollment,