[API/Usos] Remove non-digit characters from student number (#189)

* Save only USOS ID number without indexes

* Checking student number is or is not empty

* Apply suggestions from code review

---------

Co-authored-by: Kuba Szczodrzyński <kuba@szczodrzynski.pl>
This commit is contained in:
Mateusz T 2024-07-07 22:24:50 +02:00 committed by GitHub
parent f10bc42c7b
commit c5b173b40a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View File

@ -53,7 +53,7 @@ class UsosApiUser(
data.studentId = json.getInt("id") ?: data.studentId
profile?.studentNameLong = studentName
profile?.studentNameShort = studentName.getShortName()
profile?.studentNumber = json.getInt("student_number", -1)
profile?.studentNumber = json.getString("student_number")?.replace(Regex("[^0-9]"), "")?.toIntOrNull() ?: -1
profile?.studentClassName = programmes.getJsonObject(0).getJsonObject("programme").getString("id")
profile?.studentClassName?.let {

View File

@ -68,7 +68,7 @@ class UsosFirstLogin(val data: DataUsos, val onSuccess: () -> Unit) {
"studentId" to json.getInt("id"),
),
).also {
it.studentNumber = json.getInt("student_number", -1)
it.studentNumber = json.getString("student_number")?.replace(Regex("[^0-9]"), "")?.toIntOrNull() ?: -1
it.studentClassName = programmes.getJsonObject(0).getJsonObject("programme").getString("id")
}