Skip to content

Commit f6fe30c

Browse files
committed
refactor: Move another helper function to utils and fix types
1 parent 0543fba commit f6fe30c

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/server/models/courseUnit.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import {
88
InferCreationAttributes,
99
CreationOptional,
1010
DATE,
11+
NonAttribute,
1112
} from 'sequelize'
1213
import type { LocalizedString } from '@common/types/common'
1314
import { sequelize } from '../db/dbConnection'
1415
import { logger } from '../util/logger'
1516
import type Summary from './summary'
1617
import { Organisation } from './organisation'
17-
import { CourseRealisation } from './courseRealisation'
18+
import type { CourseRealisation } from './courseRealisation'
19+
import type { FeedbackTarget } from './feedbackTarget'
1820

1921
export type CourseUnitValidityPeriod = {
2022
startDate: Date
@@ -38,6 +40,7 @@ class CourseUnit extends Model<InferAttributes<CourseUnit>, InferCreationAttribu
3840
// -----------------------------
3941
declare summary?: Summary
4042
declare courseRealisations?: CourseRealisation[]
43+
declare feedbackTargets?: NonAttribute<FeedbackTarget[]>
4144

4245
// --- Helper methods ---
4346
// ----------------------

src/server/models/organisation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { LocalizedString } from '@common/types/common'
1616
import { sequelize } from '../db/dbConnection'
1717
import type Summary from './summary'
1818
import type { CourseUnit } from './courseUnit'
19+
import type { CourseRealisationsOrganisation } from './courseRealisationsOrganisation'
1920

2021
class Organisation extends Model<InferAttributes<Organisation>, InferCreationAttributes<Organisation>> {
2122
// --- Acual DB columns ---
@@ -35,6 +36,7 @@ class Organisation extends Model<InferAttributes<Organisation>, InferCreationAtt
3536
// -----------------------------
3637
declare summary?: Summary
3738
declare courseUnits?: NonAttribute<CourseUnit[]>
39+
declare courseRealisationsOrganisations?: NonAttribute<CourseRealisationsOrganisation[]>
3840

3941
// --- Helper methods ---
4042
// ----------------------

src/server/services/summary/exportXLSX.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ const {
1212
CourseRealisation,
1313
CourseUnitsOrganisation,
1414
} = require('../../models')
15-
const { getScopedSummary, sumSummaries, getOrganisationCodeById, mapCourseIdsToCourseCodes } = require('./utils')
15+
const {
16+
getScopedSummary,
17+
sumSummaries,
18+
getOrganisationCodeById,
19+
mapCourseIdsToCourseCodes,
20+
getOrganisationCourseRealisationIds,
21+
} = require('./utils')
1622
const { SUMMARY_EXCLUDED_ORG_IDS } = require('../../util/config')
1723
const { i18n } = require('../../util/i18n')
1824
const { getTeacherSummary } = require('./getTeacherSummary')
@@ -175,11 +181,6 @@ const getJSON = (targets, targetType) => {
175181
return targetJSON
176182
}
177183

178-
const getOrganisationCourseRealisationIds = (organisations, courseUnits) =>
179-
organisations
180-
.flatMap(org => org.courseRealisationsOrganisations.map(curo => curo.courseRealisationId))
181-
.concat(courseUnits.flatMap(cu => cu.feedbackTargets.map(fbt => fbt.courseRealisationId)))
182-
183184
const exportXLSX = async ({
184185
user,
185186
startDate,

src/server/services/summary/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import _ from 'lodash'
22
import * as datefns from 'date-fns'
33
import { FeedbackData } from 'models/feedback'
44
import { WORKLOAD_QUESTION_ID_ORDER, WORKLOAD_QUESTION_ID } from '../../util/config'
5-
import { Summary, Organisation, CourseRealisation } from '../../models'
5+
import { Summary, Organisation, CourseUnit, CourseRealisation } from '../../models'
66
import { SummaryData, SummaryResult } from '../../models/summary'
77

88
const mapOptionIdToValue = (optionId: string, questionId: string | number) => {
@@ -269,11 +269,17 @@ const mapCourseIdsToCourseCodes = (teacherOrganisations: Organisation[], courseR
269269
return curIdToCourseCodeMapping
270270
}
271271

272+
const getOrganisationCourseRealisationIds = (organisations: Organisation[], courseUnits: CourseUnit[]) =>
273+
organisations
274+
.flatMap(org => org.courseRealisationsOrganisations.map(curo => curo.courseRealisationId))
275+
.concat(courseUnits.flatMap(cu => cu.feedbackTargets.map(fbt => fbt.courseRealisationId)))
276+
272277
export {
273278
sumSummaryDatas,
274279
mapOptionIdToValue,
275280
sumSummaries,
276281
getScopedSummary,
277282
getOrganisationCodeById,
278283
mapCourseIdsToCourseCodes,
284+
getOrganisationCourseRealisationIds,
279285
}

0 commit comments

Comments
 (0)