-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e86b327
commit 0e2c546
Showing
3 changed files
with
69 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
services/frontend/src/components/Teachers/TeacherStatistics/mapToProviders.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Identical logic can be found in the backend (src/util/map.js) | ||
// If the logic changes, remember to update the backend as well | ||
|
||
const handleUnderscoreProgrammeCode = programmeCode => { | ||
const [left, right] = programmeCode.split('_') | ||
const prefix = [...left].filter(char => !Number.isNaN(Number(char))).join('') | ||
const suffix = `${left[0]}${right}` | ||
return `${prefix}0-${suffix}` | ||
} | ||
|
||
const handleDoctoralProgrammeCode = programmeCode => { | ||
const numbers = programmeCode.substring(1) | ||
const courseProvider = Number(`7${numbers}`) | ||
if (courseProvider < 7920111 && courseProvider > 7920102) { | ||
return `${courseProvider + 1}` | ||
} | ||
if (courseProvider === 7920111) { | ||
return '7920103' | ||
} | ||
return `${courseProvider}` | ||
} | ||
|
||
export const mapToProviders = programmeCodes => { | ||
return programmeCodes.map(programmeCode => { | ||
if (programmeCode.includes('_')) { | ||
return handleUnderscoreProgrammeCode(programmeCode) | ||
} | ||
if (/^(T)[0-9]{6}$/.test(programmeCode)) { | ||
return handleDoctoralProgrammeCode(programmeCode) | ||
} | ||
return programmeCode | ||
}) | ||
} |