Skip to content

Commit

Permalink
[Study programmes] Try to optimize Programme courses
Browse files Browse the repository at this point in the history
  • Loading branch information
valtterikantanen committed Sep 23, 2024
1 parent 053a20f commit 76c037d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
31 changes: 19 additions & 12 deletions services/backend/src/services/studyProgramme/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,41 @@ export const getNotCompletedForProgrammeCourses = async (from: Date, to: Date, p

const credits = await Credit.findAll({
attributes: ['course_code', 'student_studentnumber', 'credittypecode', 'isStudyModule'],
include: {
model: Course,
attributes: ['code', 'name'],
required: true,
where: {
code: programmeCourses,
},
},
where: {
course_code: {
[Op.in]: programmeCourses,
},
attainment_date: {
[Op.between]: [from, to],
},
},
})

const courseNames = (
await Course.findAll({
attributes: ['code', 'name'],
where: {
code: programmeCourses,
},
})
).reduce<Map<string, Name>>((acc, val) => {
acc.set(val.code, val.name)
return acc
}, new Map())

const creditCourses = credits.map(credit => {
return {
code: getCourseCode(credit.course_code),
studentNumber: credit.student_studentnumber,
creditTypeCode: credit.credittypecode,
courseName: credit.course.name,
courseName: courseNames.get(credit.course_code)!,
isStudyModule: credit.isStudyModule,
}
})

const passedByCourseCodes = {} as Record<string, string[]>
const notCompletedByCourseCodes = {} as Record<string, string[]>
const courses = {} as Record<string, { code: string; name: Name; isStudyModule: boolean }>
const courses: Record<string, { code: string; name: Name; isStudyModule: boolean }> = {}
for (const course of creditCourses) {
if (!(course.code in courses)) {
courses[course.code] = {
Expand Down Expand Up @@ -126,9 +133,9 @@ export const getNotCompletedForProgrammeCourses = async (from: Date, to: Date, p
})

return Object.keys(courses)
.reduce(
.reduce<Array<{ code: string; name: Name; isStudyModule: boolean }>>(
(acc, val) => [...acc, { ...courses[val] }],
[] as Array<{ code: string; name: Name; isStudyModule: boolean }>
[]
)
.map(course => ({
code: course.code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,6 @@ export const getOwnStudentsForProgrammeCourses = async (
INNER JOIN
course co
ON cr.course_code = co.code
INNER JOIN
course_providers cp
ON cp.coursecode = co.id
INNER JOIN
organization o
ON o.id = cp.organizationcode
WHERE
cr.attainment_date BETWEEN :from AND :to
AND cr.course_code IN (:programmeCourses)
Expand Down

0 comments on commit 76c037d

Please sign in to comment.