[CourseStats] Add better handling for invalid values

This commit is contained in:
Aaro Koivukangas
2026-05-24 21:53:26 +03:00
committed by Aaro Koivukangas
parent 25fb4bad84
commit 043b0d2cbd
3 changed files with 4 additions and 3 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ router.get<never, CanError<CourseYearlyStatsResBody>, CourseYearlyStatsReqBody,
const courseCodes = handleQueryArrays(codes)
if (!courseCodes) {
if (!courseCodes?.length) {
return res.status(422).send({ error: 'Missing required query parameters' })
}
@@ -88,7 +88,6 @@ export const getCreditsForCourses = async (codeGroups: string[][], unification:
}
}
// return completedGroups
return completedGroups.filter(group => group.length)
}
@@ -4,6 +4,7 @@ import { Op, fn as dbFn, col as dbCol } from 'sequelize'
import { Credit, Enrollment } from '@oodikone/shared/models'
import { Name, EnrollmentState, Unification } from '@oodikone/shared/types'
import { dateIsBetween } from '@oodikone/shared/util/datetime'
import logger from '../../../src/util/logger'
import { CourseModel, CreditModel, EnrollmentModel, OrganizationModel, SISStudyRightElementModel } from '../../models'
import { isOpenUniCourseCode } from '../../util'
import { CourseYearlyStatsCounter } from './courseYearlyStatsCounter'
@@ -333,7 +334,8 @@ export const getCourseYearlyStats = async (
})
if (!course) {
return null
logger.error('Course for course stats not found with code' + courseCode)
return {}
}
const [openStats, regularStats, unifyStats] = await Promise.all([