diff --git a/services/backend/src/services/populations/getStudentsIncludeCoursesBetween.ts b/services/backend/src/services/populations/getStudentsIncludeCoursesBetween.ts index af74ac25f8..7ac2ebd4ce 100644 --- a/services/backend/src/services/populations/getStudentsIncludeCoursesBetween.ts +++ b/services/backend/src/services/populations/getStudentsIncludeCoursesBetween.ts @@ -1,11 +1,9 @@ import moment from 'moment' -import { col, literal, Op, QueryTypes } from 'sequelize' +import { col, literal, Op } from 'sequelize' -import { dbConnections } from '../../database/connection' import { Course, Credit, - ElementDetail, Enrollment, Student, Studyplan, @@ -19,8 +17,6 @@ import { import { Tag, TagStudent } from '../../models/kone' import { EnrollmentState } from '../../types' -const { sequelize } = dbConnections - const getStudentTags = async (studyRights: string[], studentNumbers: string[]) => { return await TagStudent.findAll({ attributes: ['tag_id', 'studentnumber'], @@ -238,26 +234,12 @@ const getSemesters = async (studentNumbers: string[], startDate: string, endDate }) } -const getElementDetails = async (studentNumbers: string[]) => { - const elementDetails: Array> = await sequelize.query( - `SELECT DISTINCT ON (code) code, name, type FROM element_details WHERE - EXISTS (SELECT 1 FROM transfers WHERE studentnumber IN (:studentNumbers) AND (code = sourcecode OR code = targetcode)) OR - EXISTS (SELECT 1 FROM studyright_elements WHERE studentnumber IN (:studentNumbers) AND element_details.code = studyright_elements.code)`, - { - replacements: { studentNumbers }, - type: QueryTypes.SELECT, - } - ) - return elementDetails -} - type StudentsIncludeCoursesBetween = { students: Awaited> enrollments: Awaited> credits: Awaited> extents: Awaited> semesters: Awaited> - elementdetails: Awaited> courses: Awaited> } @@ -302,27 +284,18 @@ export const getStudentsIncludeCoursesBetween = async ( const creditsOfStudent = await getCreditsOfStudent(studentNumbers, studyRights, attainmentDateFrom, endDate) - const [courses, enrollments, students, credits, extents, semesters, elementdetails] = await Promise.all([ + const [courses, enrollments, students, credits, extents, semesters] = await Promise.all([ getCourses(creditsOfStudent), getEnrollments(studentNumbers, attainmentDateFrom, endDate), getStudents(studentNumbers), getCredits(creditsOfStudent), getExtents(), getSemesters(studentNumbers, startDate, endDate), - getElementDetails(studentNumbers), ]) students.forEach(student => { student.tags = studentNumberToTags[student.studentnumber] || [] }) - return { - students, - enrollments, - credits, - extents, - semesters, - elementdetails, - courses, - } as StudentsIncludeCoursesBetween + return { students, enrollments, credits, extents, semesters, courses } as StudentsIncludeCoursesBetween } diff --git a/services/backend/src/services/populations/optimizedStatisticsOf.ts b/services/backend/src/services/populations/optimizedStatisticsOf.ts index 8d55fe46c8..316e47a910 100644 --- a/services/backend/src/services/populations/optimizedStatisticsOf.ts +++ b/services/backend/src/services/populations/optimizedStatisticsOf.ts @@ -57,17 +57,16 @@ export const optimizedStatisticsOf = async (query: Query, studentNumberList?: st if (code.includes('KH') || ['MH30_001', 'MH30_003'].includes(code)) { criteria = await getCriteria(code) } - const { students, enrollments, credits, extents, semesters, elementdetails, courses } = - await getStudentsIncludeCoursesBetween( - studentNumbers, - startDate, - dateMonthsFromNow(startDate, months), - studyRights, - tag - ) + const { students, enrollments, credits, extents, semesters, courses } = await getStudentsIncludeCoursesBetween( + studentNumbers, + startDate, + dateMonthsFromNow(startDate, months), + studyRights, + tag + ) const formattedStudents = await formatStudentsForApi( - { students, enrollments, credits, extents, semesters, elementdetails, courses }, + { students, enrollments, credits, extents, semesters, courses }, startDate, endDate, studyRights, diff --git a/services/backend/src/services/populations/shared.ts b/services/backend/src/services/populations/shared.ts index c6c45db463..2d7f6e8e62 100644 --- a/services/backend/src/services/populations/shared.ts +++ b/services/backend/src/services/populations/shared.ts @@ -4,7 +4,7 @@ import { Op, QueryTypes } from 'sequelize' import { dbConnections } from '../../database/connection' import { Course, Credit, SISStudyRight, SISStudyRightElement } from '../../models' -import { ElementDetailType, Criteria, Name } from '../../types' +import { Criteria, Name } from '../../types' import { SemesterStart } from '../../util/semester' import { getCurrentSemester } from '../semesters' @@ -332,7 +332,7 @@ export const getOptionsForStudents = async (studentNumbers: string[], code: stri } export const formatStudentsForApi = async ( - { students, enrollments, credits, extents, semesters, elementdetails, courses }, + { students, enrollments, credits, extents, semesters, courses }, startDate: string, endDate: string, studyRights: string[], @@ -344,16 +344,6 @@ export const formatStudentsForApi = async ( const endDateMoment = moment(endDate) const currentSemester = (await getCurrentSemester()).semestercode - elementdetails = elementdetails.reduce( - (acc, elementDetail) => { - acc.data[elementDetail.code] = elementDetail - if (elementDetail.type === ElementDetailType.PROGRAMME) { - acc.programmes.push(elementDetail.code) - } - return acc - }, - { programmes: [], data: {} } - ) credits = credits.reduce((acc, credit) => { acc[credit.student_studentnumber] = acc[credit.student_studentnumber] || [] acc[credit.student_studentnumber].push(credit) @@ -426,16 +416,13 @@ export const formatStudentsForApi = async ( return student } - const returnvalue = { + return { students: result.students.map(transferredStudyright), transfers: result.transfers, extents, semesters, courses, - elementdetails, } - - return returnvalue } export const formatQueryParamsToArrays = (query: Record, params: string[]) => { diff --git a/services/backend/src/services/students.ts b/services/backend/src/services/students.ts index 9c0ea2d1c9..863d262429 100644 --- a/services/backend/src/services/students.ts +++ b/services/backend/src/services/students.ts @@ -5,7 +5,7 @@ import { Student, Credit, Course, - ElementDetail, + ProgrammeModule, SemesterEnrollment, Semester, Studyplan, @@ -83,8 +83,10 @@ const byStudentNumber = async (studentNumber: string) => { ], }), TagStudent.findAll({ + attributes: ['tag_id'], include: { model: Tag, + attributes: ['personal_user_id', 'studytrack', 'tagname', 'year'], }, where: { studentnumber: studentNumber, @@ -92,7 +94,8 @@ const byStudentNumber = async (studentNumber: string) => { }), ]) if (!student) return null - const tagprogrammes = await ElementDetail.findAll({ + const tagprogrammes = await ProgrammeModule.findAll({ + attributes: ['code', 'name'], where: { code: { [Op.in]: tags.map(tag => tag.tag.studytrack), @@ -303,7 +306,9 @@ const formatSharedStudentData = ({ const formatStudent = ( studentData: Partial> & { semester_enrollments: SemesterEnrollmentWithNameAndYear[] - } & { tags: Array & { programme?: ElementDetail }> } + } & { + tags: Array & { programme?: Pick, 'code' | 'name'> }> + } ) => { const formattedData = formatSharedStudentData(studentData) return { diff --git a/services/frontend/src/components/PopulationStudents/StudentTable/GeneralTab/GeneralTab.jsx b/services/frontend/src/components/PopulationStudents/StudentTable/GeneralTab/GeneralTab.jsx index c570013ff5..fec2a36011 100644 --- a/services/frontend/src/components/PopulationStudents/StudentTable/GeneralTab/GeneralTab.jsx +++ b/services/frontend/src/components/PopulationStudents/StudentTable/GeneralTab/GeneralTab.jsx @@ -11,6 +11,7 @@ import { useLanguage } from '@/components/LanguagePicker/useLanguage' import { SortableTable } from '@/components/SortableTable' import { DISPLAY_DATE_FORMAT, ISO_DATE_FORMAT, ISO_DATE_FORMAT_DEV } from '@/constants/date' import { useGetAuthorizedUserQuery } from '@/redux/auth' +import { useGetProgrammesQuery } from '@/redux/populations' import { useGetSemestersQuery } from '@/redux/semesters' import { reformatDate } from '@/util/timeAndDate' import { createMaps } from './columnHelpers/createMaps' @@ -37,6 +38,7 @@ export const GeneralTab = ({ return obj }, {}) const { isAdmin } = useGetAuthorizedUserQuery() + const { data: programmes = {} } = useGetProgrammesQuery() const fromSemester = from ? Object.values(semesterData.semesters) @@ -60,7 +62,7 @@ export const GeneralTab = ({ const currentSemester = useCurrentSemester() - if (!populationStatistics || !populationStatistics.elementdetails) return null + if (!populationStatistics) return null const studyGuidanceGroupProgrammes = group?.tags?.studyProgramme && group?.tags?.studyProgramme.includes('+') @@ -120,7 +122,7 @@ export const GeneralTab = ({ currentSemester: currentSemester?.semestercode, }) - const transferFrom = student => getTextIn(populationStatistics.elementdetails.data[student.transferSource].name) + const transferFrom = student => getTextIn(programmes[student.transferSource]?.name) ?? student.transferSource const getCorrectStudyRight = studyRights => studyRights?.find(studyRight =>