Skip to content

Commit

Permalink
[Study programme overview] Credits produced: Improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Aug 12, 2024
1 parent 3648d5d commit f80a92d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions services/backend/src/services/providerCredits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ export const computeCreditsProduced = async (providerCode: string, isAcademicYea
const vaasaCodes = {
'200-K001': '200-K0012',
'200-M001': '200-M0012',
}
const vaasaProvider = vaasaCodes[rapoFormattedProviderCode]
} as const
const vaasaProvider =
rapoFormattedProviderCode in vaasaCodes ? vaasaCodes[rapoFormattedProviderCode as keyof typeof vaasaCodes] : null
if (vaasaProvider) {
const courses = await getCourseCodesOfProvider(vaasaProvider)
const vaasaCredits = await getCreditsForProvider(vaasaProvider, courses, since)
Expand All @@ -125,20 +126,23 @@ export const computeCreditsProduced = async (providerCode: string, isAcademicYea

const studyRights = await getSISStudyRightsOfStudents(students)

const studyRightIdToStudyRightMap = studyRights.reduce((obj, cur) => {
const studyRightIdToStudyRightMap = studyRights.reduce<Record<string, InferAttributes<SISStudyRight>>>((obj, cur) => {
obj[cur.id] = cur
return obj
}, {})

const studentNumberToStudyRightsMap = studyRights.reduce((obj, cur) => {
if (!obj[cur.studentNumber]) {
obj[cur.studentNumber] = []
}
obj[cur.studentNumber].push(cur)
return obj
}, {})

const stats = {}
const studentNumberToStudyRightsMap = studyRights.reduce<Record<string, Array<InferAttributes<SISStudyRight>>>>(
(obj, cur) => {
if (!obj[cur.studentNumber]) {
obj[cur.studentNumber] = []
}
obj[cur.studentNumber].push(cur)
return obj
},
{}
)

const stats: Record<string, Record<string, number>> = {}

for (const { attainmentDate, studentNumber, credits: numOfCredits, studyrightId, semestercode } of credits) {
const studyRightLinkedToAttainment = studyRightIdToStudyRightMap[studyrightId]
Expand Down

0 comments on commit f80a92d

Please sign in to comment.