From f80a92db181d277e182d9da858a5c340127c23f8 Mon Sep 17 00:00:00 2001 From: Valtteri Kantanen Date: Mon, 12 Aug 2024 16:01:30 +0300 Subject: [PATCH] [Study programme overview] Credits produced: Improve types --- .../backend/src/services/providerCredits.ts | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/services/backend/src/services/providerCredits.ts b/services/backend/src/services/providerCredits.ts index 57dbc97e41..07f038abbd 100644 --- a/services/backend/src/services/providerCredits.ts +++ b/services/backend/src/services/providerCredits.ts @@ -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) @@ -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>>((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>>>( + (obj, cur) => { + if (!obj[cur.studentNumber]) { + obj[cur.studentNumber] = [] + } + obj[cur.studentNumber].push(cur) + return obj + }, + {} + ) + + const stats: Record> = {} for (const { attainmentDate, studentNumber, credits: numOfCredits, studyrightId, semestercode } of credits) { const studyRightLinkedToAttainment = studyRightIdToStudyRightMap[studyrightId]