[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 { SISStudyRight, SISStudyRightElement, Student, Studyplan } from '@oodikone/shared/models'
import { Tag, TagStudent } from '@oodikone/shared/models/kone' import { Tag, TagStudent } from '@oodikone/shared/models/kone'
@@ -12,6 +12,7 @@ import {
StudyplanModel, StudyplanModel,
SISStudyRightModel, SISStudyRightModel,
SISStudyRightElementModel, SISStudyRightElementModel,
CourseModel,
} from '../../models' } from '../../models'
import { TagModel, TagStudentModel } from '../../models/kone' import { TagModel, TagStudentModel } from '../../models/kone'
import { StudentCredit, StudentEnrollment } from '@oodikone/shared/types/studentData' 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 }))) }).then(data => data.map(x => x.get({ plain: true })))
export const getCredits = async ( export const getCredits = async (studentNumbers: string[], startDate: string, endDate: string) =>
studentNumbers: string[],
startDate: string,
endDate: string
): Promise<StudentCredit[]> =>
CreditModel.findAll({ CreditModel.findAll({
raw: true, raw: true,
attributes: [ attributes: [
@@ -208,12 +205,19 @@ export const getCredits = async (
'course_code', 'course_code',
'language', 'language',
'studyright_id', 'studyright_id',
[col('course.group_id'), 'courseGroupId'],
], ],
include: {
model: CourseModel,
attributes: [],
as: 'course',
required: true,
},
where: { where: {
student_studentnumber: { [Op.in]: studentNumbers }, student_studentnumber: { [Op.in]: studentNumbers },
attainment_date: { [Op.between]: [startDate, endDate] }, attainment_date: { [Op.between]: [startDate, endDate] },
}, },
}) }) as unknown as Promise<StudentCredit[]>
export const getStudyRightElementsForStudyRight = async (studentNumbers: string[], code: string) => export const getStudyRightElementsForStudyRight = async (studentNumbers: string[], code: string) =>
SISStudyRightElementModel.findAll({ SISStudyRightElementModel.findAll({
@@ -71,6 +71,7 @@ export const formatPopulationData = <T extends RequiredFields>(
return { return {
course_id: credit.course_id, course_id: credit.course_id,
course_code: credit.course_code, course_code: credit.course_code,
courseGroupId: credit.courseGroupId,
date: credit.attainment_date, date: credit.attainment_date,
passed, passed,
grade: passed ? credit.grade : 'Hyl.', 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 { Tag, TagStudent } from '../models/kone'
import type { CriteriaYear, CreditTypeCode, Name, ProgrammeModule } from '../types' import type { CriteriaYear, CreditTypeCode, Name, ProgrammeModule } from '../types'
@@ -115,6 +115,7 @@ export type StudentCourse = {
credittypecode: CreditTypeCode credittypecode: CreditTypeCode
language: string language: string
studyright_id: string studyright_id: string
courseGroupId: Course['groupId']
} }
export type StudentCredit = Pick< export type StudentCredit = Pick<
@@ -129,7 +130,7 @@ export type StudentCredit = Pick<
| 'course_code' | 'course_code'
| 'language' | 'language'
| 'studyright_id' | 'studyright_id'
> > & { courseGroupId: Course['groupId'] }
export type StudentEnrollment = Pick< export type StudentEnrollment = Pick<
Enrollment, Enrollment,