Skip to content

Commit

Permalink
feat: update the course unit logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HRemonen committed May 13, 2024
1 parent f77ad5b commit 6c10b19
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ const getIncludeCurs = async () => {
const getCourseUnit = ({ activityPeriod, courseUnits, name }) => {
const { startDate: realisationStartDate } = activityPeriod

const latestCourseUnit = courseUnits.sort((a, b) => {
const { startDate: aStartDate } = a.validityPeriod
const { startDate: bStartDate } = b.validityPeriod

if (!aStartDate || !bStartDate) return 0

return dateFns.isAfter(new Date(aStartDate), new Date(bStartDate)) ? -1 : 1
})[0]

const scientificallyAccurateCUs = courseUnits.map((courseUnit) => {
const getSimilarityRanking = (language) => stringSimilarity(name[language] ?? '', courseUnit.name[language] ?? '')

Expand Down Expand Up @@ -143,7 +152,8 @@ const getCourseUnit = ({ activityPeriod, courseUnits, name }) => {
return dateFns.isAfter(new Date(realisationStartDate), new Date(startDate))
}) ?? sortedCourseUnits[0]

return courseUnit

return latestCourseUnit.code === courseUnit.code ? latestCourseUnit : courseUnit
}

const getResponsibilityInfos = (_courseUnit, courseRealisation) => {
Expand Down

0 comments on commit 6c10b19

Please sign in to comment.