Skip to content

Commit

Permalink
[Updater] Fix study plans not including all the courses in student's …
Browse files Browse the repository at this point in the history
…study plan (#4390)
  • Loading branch information
valtterikantanen committed Mar 20, 2024
1 parent 268fc7c commit 57cad29
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
12 changes: 6 additions & 6 deletions updater/sis-updater-worker/src/updater/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,14 @@ const studyplanMapper =
const graduated = moduleAttainments[programmeId] && moduleAttainments[programmeId][studyplan.user_id]
const id = `${studentnumber}-${code}-${studyrightId}`
const courseUnitSelections = studyplan.course_unit_selections
.filter(courseUnit => moduleIdToParentModuleCode[courseUnit.parentModuleId] === code)
.filter(courseUnit => moduleIdToParentModuleCode[courseUnit.parentModuleId]?.has(code))
.filter(({ substituteFor }) => !substituteFor.length) // Filter out CUs used to substitute another CU
.map(({ substitutedBy, courseUnitId }) => {
if (substitutedBy.length) return courseUnitIdToCode[substitutedBy[0]]
return courseUnitIdToCode[courseUnitId]
})
const customCourseUnitSelections = studyplan.custom_course_unit_attainment_selections
.filter(({ parentModuleId }) => moduleIdToParentModuleCode[parentModuleId] === code)
.filter(({ parentModuleId }) => moduleIdToParentModuleCode[parentModuleId]?.has(code))
.map(({ customCourseUnitAttainmentId }) => (attainmentIdToAttainment[customCourseUnitAttainmentId] || {}).code)
.map(sanitizeCourseCode)
.filter(c => !!c)
Expand All @@ -421,7 +421,7 @@ const studyplanMapper =
studyplan.module_selections
.filter(
({ moduleId }) =>
moduleIdToParentModuleCode[moduleId] === code &&
moduleIdToParentModuleCode[moduleId]?.has(code) &&
moduleAttainments[moduleId] &&
moduleAttainments[moduleId][studyplan.user_id]
)
Expand All @@ -432,12 +432,12 @@ const studyplanMapper =
graduated
? getAttainmentsFromAttainment(moduleAttainments[programmeId][studyplan.user_id])
: studyplan.custom_course_unit_attainment_selections
.filter(({ parentModuleId }) => moduleIdToParentModuleCode[parentModuleId] === code)
.filter(({ parentModuleId }) => moduleIdToParentModuleCode[parentModuleId]?.has(code))
.map(({ customCourseUnitAttainmentId }) => attainmentIdToAttainment[customCourseUnitAttainmentId])
.concat(
flatten(
studyplan.course_unit_selections
.filter(courseUnit => moduleIdToParentModuleCode[courseUnit.parentModuleId] === code)
.filter(courseUnit => moduleIdToParentModuleCode[courseUnit.parentModuleId]?.has(code))
.filter(({ substituteFor }) => !substituteFor.length) // Filter out CUs used to substitute another CU
.map(({ substitutedBy, courseUnitId }) => {
if (substitutedBy.length) {
Expand Down Expand Up @@ -479,7 +479,7 @@ const studyplanMapper =
studyplan.module_selections
.filter(
({ moduleId }) =>
moduleIdToParentModuleCode[moduleId] === code &&
moduleIdToParentModuleCode[moduleId]?.has(code) &&
moduleAttainments[moduleId] &&
moduleAttainments[moduleId][studyplan.user_id]
)
Expand Down
28 changes: 16 additions & 12 deletions updater/sis-updater-worker/src/updater/updateStudents/studyPlans.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe
return res
}, {})

const programmeModuleGroupIdToCode = programmeModules.reduce((res, cur) => {
res[cur.id] = cur.code
return res
}, {})

const courseUnitIdToCode = courseUnits.reduce((res, cur) => {
res[cur.id] = cur.code
return res
Expand Down Expand Up @@ -146,7 +141,7 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe
if (attainment.code) return [attainment.code]

const { course_unit_id, module_id } = attainment
const code = courseUnitIdToCode[course_unit_id] || programmeModuleGroupIdToCode[module_id]
const code = courseUnitIdToCode[course_unit_id] || programmeModuleIdToCode[module_id]
if (!code) return []
return [code]
}
Expand All @@ -169,7 +164,10 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe

const moduleIdToParentDegreeProgramme = {}
const mapParentDegreeProgrammes = (moduleId, degreeProgrammeId) => {
moduleIdToParentDegreeProgramme[moduleId] = degreeProgrammeId
if (!moduleIdToParentDegreeProgramme[moduleId]) {
moduleIdToParentDegreeProgramme[moduleId] = []
}
moduleIdToParentDegreeProgramme[moduleId].push(degreeProgrammeId)
if (!childModules[moduleId]) return

childModules[moduleId].forEach(child => {
Expand All @@ -189,11 +187,17 @@ const updateStudyplans = async (studyplansAll, personIds, personIdToStudentNumbe
return res
}, {})

const moduleIdToParentModuleCode = Object.keys(moduleIdToParentDegreeProgramme).reduce((acc, cur) => {
const parent = moduleIdToParentDegreeProgramme[cur]
acc[cur] = programmeModuleGroupIdToCode[parent]
return acc
}, {})
const moduleIdToParentModuleCode = Object.entries(moduleIdToParentDegreeProgramme).reduce(
(acc, [moduleId, degreeProgrammeIds]) => {
const codes = new Set()
for (const programmeId of degreeProgrammeIds) {
codes.add(programmeModuleIdToCode[programmeId])
}
acc[moduleId] = codes
return acc
},
{}
)

const mapStudyplan = studyplanMapper(
personIdToStudentNumber,
Expand Down

0 comments on commit 57cad29

Please sign in to comment.