[Backend][statisticsOf] add course groupId to student credits

This commit is contained in:
joonas-a
2026-09-29 14:58:21 +03:00
parent fa21354b8b
commit fef7faa8e7
3 changed files with 15 additions and 9 deletions
@@ -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<Array<StudentData
},
}).then(data => data.map(x => x.get({ plain: true })))
export const getCredits = async (
studentNumbers: string[],
startDate: string,
endDate: string
): Promise<StudentCredit[]> =>
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<StudentCredit[]>
export const getStudyRightElementsForStudyRight = async (studentNumbers: string[], code: string) =>
SISStudyRightElementModel.findAll({
@@ -71,6 +71,7 @@ export const formatPopulationData = <T extends RequiredFields>(
return {
course_id: credit.course_id,
course_code: credit.course_code,
courseGroupId: credit.courseGroupId,
date: credit.attainment_date,
passed,
grade: passed ? credit.grade : 'Hyl.',
+3 -2
View File
@@ -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,