UniversityOfHelsinkiCS / oodikone

An application for analyzing university data
https://oodikone.helsinki.fi
MIT License
14 stars 6 forks source link

Use enums for numeric types #4565

Closed rikurauhala closed 2 months ago

rikurauhala commented 2 months ago

Oodikone has a lot of numeric types that are difficult to remember and have to be constantly referenced. They have now been properly documented but TypeScript will make dealing with them a lot easier.

Let's use enums to refer to these numeric types. This will eliminate the need to constantly reference documentation or existing code and allow quickly choosing from a list of predefined values. It will also get rid of unnecessary comments to explain what these magic numbers mean. Using enums will also make refactoring easier if the values ever change or new options are added.

Progress:

For example, this

return mergeAbsences(
  patchedSemesterenrollments
    .filter(({ enrollmenttype }) => enrollmenttype !== 1) // 1 = present & 2 = absent
    .map(absence => formatAbsence(absence))

would become

return mergeAbsences(
  patchedSemesterenrollments
    .filter(({ enrollmenttype }) => enrollmenttype !== EnrollmentType.PRESENT)
    .map(absence => formatAbsence(absence))
rikurauhala commented 2 months ago

Enums are now in use in all relevant places in the backend.