@kth/om-kursen-ladok-client 2.0.5 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attributVardenConstants.js +1 -0
- package/dist/attributVardenConstants.js.map +1 -1
- package/dist/cache.d.ts +17 -0
- package/dist/cache.js +54 -0
- package/dist/cache.js.map +1 -0
- package/dist/createApiClient.js +5 -30
- package/dist/createApiClient.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/{mapProgramInstans.d.ts → mapProgrammeVersion.d.ts} +7 -4
- package/dist/{mapProgramInstans.js → mapProgrammeVersion.js} +16 -6
- package/dist/mapProgrammeVersion.js.map +1 -0
- package/dist/programme/createProgrammeApi.d.ts +3 -0
- package/dist/programme/createProgrammeApi.js +53 -0
- package/dist/programme/createProgrammeApi.js.map +1 -0
- package/dist/programme/types.d.ts +19 -0
- package/dist/programme/types.js +3 -0
- package/dist/programme/types.js.map +1 -0
- package/dist/programme/utbildningsTypIdConstants.d.ts +4 -0
- package/dist/programme/utbildningsTypIdConstants.js +13 -0
- package/dist/programme/utbildningsTypIdConstants.js.map +1 -0
- package/dist/programme/utils/programmeDegreeMapping.d.ts +10 -0
- package/dist/programme/utils/programmeDegreeMapping.js +55 -0
- package/dist/programme/utils/programmeDegreeMapping.js.map +1 -0
- package/dist/programme/utils/programmeVersionUtil.d.ts +9 -0
- package/dist/programme/utils/programmeVersionUtil.js +27 -0
- package/dist/programme/utils/programmeVersionUtil.js.map +1 -0
- package/dist/search/createSearchApi.js +26 -78
- package/dist/search/createSearchApi.js.map +1 -1
- package/dist/search/searchService.d.ts +24 -0
- package/dist/search/searchService.js +80 -0
- package/dist/search/searchService.js.map +1 -0
- package/dist/search/types.d.ts +15 -0
- package/dist/search/utils/educationalTypeUtils.d.ts +12 -0
- package/dist/search/utils/educationalTypeUtils.js +28 -1
- package/dist/search/utils/educationalTypeUtils.js.map +1 -1
- package/dist/search/utils/searchUtils.d.ts +23 -1
- package/dist/search/utils/searchUtils.js +53 -30
- package/dist/search/utils/searchUtils.js.map +1 -1
- package/dist/supportApis/coursesByOrgUtil.d.ts +32 -0
- package/dist/supportApis/coursesByOrgUtil.js +55 -0
- package/dist/supportApis/coursesByOrgUtil.js.map +1 -0
- package/dist/supportApis/createSupportApis.d.ts +10 -11
- package/dist/supportApis/createSupportApis.js +10 -114
- package/dist/supportApis/createSupportApis.js.map +1 -1
- package/dist/supportApis/organisationService.d.ts +12 -0
- package/dist/supportApis/organisationService.js +42 -0
- package/dist/supportApis/organisationService.js.map +1 -0
- package/dist/supportApis/searchSupportUtil.d.ts +13 -0
- package/dist/supportApis/searchSupportUtil.js +68 -0
- package/dist/supportApis/searchSupportUtil.js.map +1 -0
- package/dist/supportApis/supportService.d.ts +18 -0
- package/dist/supportApis/supportService.js +121 -0
- package/dist/supportApis/supportService.js.map +1 -0
- package/dist/supportApis/supportUtils.d.ts +60 -0
- package/dist/supportApis/supportUtils.js +116 -0
- package/dist/supportApis/supportUtils.js.map +1 -0
- package/dist/supportApis/types.d.ts +12 -0
- package/dist/supportApis/types.js +3 -0
- package/dist/supportApis/types.js.map +1 -0
- package/dist/types/OmKursenLadokApiClient.d.ts +4 -2
- package/dist/utils/AcademicSemester.d.ts +43 -0
- package/dist/utils/AcademicSemester.js +82 -0
- package/dist/utils/AcademicSemester.js.map +1 -0
- package/dist/{search → utils}/SearchError.d.ts +8 -1
- package/dist/{search → utils}/SearchError.js +9 -0
- package/dist/utils/SearchError.js.map +1 -0
- package/dist/utils/collectionUtils.d.ts +4 -0
- package/dist/utils/collectionUtils.js +19 -0
- package/dist/utils/collectionUtils.js.map +1 -0
- package/dist/utils/creditsUtil.js +1 -0
- package/dist/utils/creditsUtil.js.map +1 -1
- package/dist/utils/errorUtils.d.ts +1 -1
- package/dist/utils/errorUtils.js +1 -1
- package/dist/utils/errorUtils.js.map +1 -1
- package/dist/{search/utils → utils}/getAllEntitiesByUseOfContinuation.d.ts +2 -1
- package/dist/{search/utils → utils}/getAllEntitiesByUseOfContinuation.js +5 -5
- package/dist/utils/getAllEntitiesByUseOfContinuation.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/languageUtil.d.ts +12 -9
- package/dist/utils/languageUtil.js +14 -1
- package/dist/utils/languageUtil.js.map +1 -1
- package/dist/utils/mergeResponses.d.ts +3 -0
- package/dist/utils/mergeResponses.js +37 -0
- package/dist/utils/mergeResponses.js.map +1 -0
- package/dist/utils/periodUtil.d.ts +2 -2
- package/dist/utils/periodUtil.js.map +1 -1
- package/dist/utils/programUtil.d.ts +6 -11
- package/dist/utils/programUtil.js +21 -13
- package/dist/utils/programUtil.js.map +1 -1
- package/dist/utils/studyYearUtil.d.ts +2 -1
- package/dist/utils/studyYearUtil.js +11 -7
- package/dist/utils/studyYearUtil.js.map +1 -1
- package/package.json +3 -3
- package/dist/mapProgramInstans.js.map +0 -1
- package/dist/search/SearchError.js.map +0 -1
- package/dist/search/utils/getAllEntitiesByUseOfContinuation.js.map +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.handleSchools = void 0;
|
|
13
|
+
const supportUtils_1 = require("./supportUtils");
|
|
14
|
+
const typeChecking_1 = require("../utils/typeChecking");
|
|
15
|
+
const currentSchoolCodes = ['A', 'C', 'J', 'M', 'S', 'U'];
|
|
16
|
+
const deprecatedSchoolCodes = ['B', 'D', 'E', 'H', 'I', 'K', 'L'];
|
|
17
|
+
/**
|
|
18
|
+
* Handles the retrieval and filtering of schools and their departments based on the presence of courses.
|
|
19
|
+
*
|
|
20
|
+
* This function takes lists of organisations and organisation connections, and returns two arrays:
|
|
21
|
+
* - `current`: Schools with departments that currently have at least one course (optionally including cancelled courses and/or only third cycle courses).
|
|
22
|
+
* - `deprecated`: Deprecated schools with departments that have at least one course.
|
|
23
|
+
*
|
|
24
|
+
* The filtering is performed by checking each department using the provided `hasAtLeastOneCourse` function.
|
|
25
|
+
*
|
|
26
|
+
* @param organisationer - Array of organisation objects representing schools and departments.
|
|
27
|
+
* @param organisationskopplingar - Array of organisation connection objects describing the hierarchy.
|
|
28
|
+
* @param language - The language to use for school and department names.
|
|
29
|
+
* @param onlyThirdCycle - If true, only include departments with third cycle (research level) courses. Defaults to false.
|
|
30
|
+
* @param includeDepartmentsWithCancelledCourses - If true, include departments that have cancelled courses. Defaults to false.
|
|
31
|
+
* @param hasAtLeastOneCourse - Async function to determine if a department has at least one course, given its code and filtering options.
|
|
32
|
+
* @returns A promise resolving to an object containing arrays of current and deprecated schools with their filtered departments.
|
|
33
|
+
*/
|
|
34
|
+
const handleSchools = (_a) => __awaiter(void 0, [_a], void 0, function* ({ organisationer, organisationskopplingar, language, onlyThirdCycle = false, includeDepartmentsWithCancelledCourses = false, hasAtLeastOneCourse, }) {
|
|
35
|
+
if (!organisationer.length || !organisationskopplingar.length) {
|
|
36
|
+
return Promise.resolve({ current: [], deprecated: [] });
|
|
37
|
+
}
|
|
38
|
+
const schoolsWithDepartments = (0, supportUtils_1.getSchoolsWithDepartments)({
|
|
39
|
+
organisationer,
|
|
40
|
+
schoolCodes: [...currentSchoolCodes, ...deprecatedSchoolCodes],
|
|
41
|
+
organisationskopplingar,
|
|
42
|
+
language,
|
|
43
|
+
});
|
|
44
|
+
const departments = (0, supportUtils_1.extractDepartmentFlatsFromSchoolsWithDepartments)(schoolsWithDepartments);
|
|
45
|
+
const departmentCodesWithCourses = (yield Promise.all(departments.map((_a) => __awaiter(void 0, [_a], void 0, function* ({ code }) {
|
|
46
|
+
const hasCourses = yield hasAtLeastOneCourse(code, includeDepartmentsWithCancelledCourses, onlyThirdCycle);
|
|
47
|
+
return hasCourses ? code : null;
|
|
48
|
+
})))).filter(typeChecking_1.isDefined);
|
|
49
|
+
const schoolsWithDepartmentsFiltered = (0, supportUtils_1.filterOutDepartmentsWithoutCourses)(schoolsWithDepartments, departmentCodesWithCourses);
|
|
50
|
+
const current = schoolsWithDepartmentsFiltered.filter(school => currentSchoolCodes.includes(school.departmentPrefix));
|
|
51
|
+
const deprecated = schoolsWithDepartmentsFiltered.filter(school => deprecatedSchoolCodes.includes(school.departmentPrefix));
|
|
52
|
+
return Promise.resolve({ current, deprecated });
|
|
53
|
+
});
|
|
54
|
+
exports.handleSchools = handleSchools;
|
|
55
|
+
//# sourceMappingURL=coursesByOrgUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coursesByOrgUtil.js","sourceRoot":"","sources":["../../src/supportApis/coursesByOrgUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,iDAIuB;AAEvB,wDAAiD;AAEjD,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACzD,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEjE;;;;;;;;;;;;;;;;GAgBG;AACI,MAAM,aAAa,GAAG,KAkB0D,EAAE,4CAlBrD,EAClC,cA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AAgB,CAAC,CACxD,CAAA;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAA;AACjD,CAAC,CAAA,CAAA;AApDY,QAAA,aAAa,iBAoDzB"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { LadokMellanlagerApiClient } from '@kth/ladok-mellanlager-client';
|
|
2
2
|
import { Language } from '../utils';
|
|
3
|
-
|
|
3
|
+
import { SchoolWithDepartments } from './types';
|
|
4
4
|
export type SupportApi = {
|
|
5
5
|
createDepartmentList: (language: Language, deprecated?: boolean) => Promise<SchoolWithDepartments[]>;
|
|
6
|
+
getCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse: (params: {
|
|
7
|
+
lang: Language;
|
|
8
|
+
includeDepartmentsWithCancelledCourses?: boolean;
|
|
9
|
+
onlyThirdCycle?: boolean;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
current: SchoolWithDepartments[];
|
|
12
|
+
deprecated: SchoolWithDepartments[];
|
|
13
|
+
}>;
|
|
6
14
|
};
|
|
7
|
-
|
|
8
|
-
name: string;
|
|
9
|
-
code: string;
|
|
10
|
-
};
|
|
11
|
-
export type SchoolWithDepartments = {
|
|
12
|
-
departmentPrefix: string;
|
|
13
|
-
name: string;
|
|
14
|
-
departments: DepartmentFlat[];
|
|
15
|
-
};
|
|
16
|
-
export {};
|
|
15
|
+
export declare const createSupportApi: (ladokClient: LadokMellanlagerApiClient) => SupportApi;
|
|
@@ -10,128 +10,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.createSupportApi = void 0;
|
|
13
|
+
const organisationService_1 = require("./organisationService");
|
|
14
|
+
const supportService_1 = require("./supportService");
|
|
13
15
|
const createSupportApi = (ladokClient) => {
|
|
16
|
+
const organisationService = new organisationService_1.OrganisationService(ladokClient);
|
|
17
|
+
const supportService = new supportService_1.SupportService(ladokClient);
|
|
14
18
|
return {
|
|
15
|
-
createDepartmentList: (
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
ladokClient.organisation(),
|
|
20
|
-
]);
|
|
21
|
-
const organisationer = (_b = (_a = organisationsResponse.data) === null || _a === void 0 ? void 0 : _a.Organisationer) !== null && _b !== void 0 ? _b : [];
|
|
22
|
-
const organisationskopplingar = (_d = (_c = organisationskopplingsResponse.data) === null || _c === void 0 ? void 0 : _c.Organisationskopplingar) !== null && _d !== void 0 ? _d : [];
|
|
23
|
-
const schoolsWithDepartments = extractSchoolsWithDepartments({
|
|
19
|
+
createDepartmentList: supportService.createDepartmentList.bind(supportService),
|
|
20
|
+
getCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse: (_a) => __awaiter(void 0, [_a], void 0, function* ({ lang: language, includeDepartmentsWithCancelledCourses = false, onlyThirdCycle = false, }) {
|
|
21
|
+
const { organisationer, organisationskopplingar } = yield organisationService.getOrganisationData();
|
|
22
|
+
return supportService.getCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse({
|
|
24
23
|
organisationer,
|
|
25
24
|
organisationskopplingar,
|
|
26
25
|
language,
|
|
27
|
-
|
|
26
|
+
includeDepartmentsWithCancelledCourses,
|
|
27
|
+
onlyThirdCycle,
|
|
28
28
|
});
|
|
29
|
-
return schoolsWithDepartments;
|
|
30
29
|
}),
|
|
31
30
|
};
|
|
32
31
|
};
|
|
33
32
|
exports.createSupportApi = createSupportApi;
|
|
34
|
-
const currentSchoolCodes = ['A', 'C', 'J', 'M', 'S', 'U'];
|
|
35
|
-
const deprecatedSchoolCodes = ['D', 'K', 'H', 'L'];
|
|
36
|
-
const deprecatedOrganisationCodesToInclude = ['DM', 'KD', 'KE', 'KF', 'HA', 'HPN', 'LA', 'LPA'];
|
|
37
|
-
const currentOrganisationCodesToExclude = [
|
|
38
|
-
'AA',
|
|
39
|
-
'AD',
|
|
40
|
-
'ADA',
|
|
41
|
-
'AG',
|
|
42
|
-
'AGA',
|
|
43
|
-
'AI',
|
|
44
|
-
'AIA',
|
|
45
|
-
'AK',
|
|
46
|
-
'AKA',
|
|
47
|
-
'ALA',
|
|
48
|
-
'AM',
|
|
49
|
-
'CA',
|
|
50
|
-
'CBA',
|
|
51
|
-
'CBB',
|
|
52
|
-
'JA',
|
|
53
|
-
'MA',
|
|
54
|
-
'MAD',
|
|
55
|
-
'MAS',
|
|
56
|
-
'MFE',
|
|
57
|
-
'MK',
|
|
58
|
-
'SAC',
|
|
59
|
-
'UTHS',
|
|
60
|
-
'LA',
|
|
61
|
-
]; // TODO This is a list of organisationCodes that has neither current nor cancelled courses. We have to find a better way to do this.
|
|
62
|
-
const getSchoolCodes = (deprecated) => {
|
|
63
|
-
if (deprecated)
|
|
64
|
-
return deprecatedSchoolCodes;
|
|
65
|
-
return currentSchoolCodes;
|
|
66
|
-
};
|
|
67
|
-
const filterDepartments = (departments, deprecated) => {
|
|
68
|
-
if (deprecated) {
|
|
69
|
-
return departments.filter(department => deprecatedOrganisationCodesToInclude.includes(department.code));
|
|
70
|
-
}
|
|
71
|
-
return departments.filter(department => currentOrganisationCodesToExclude.every(code => !department.code.startsWith(code)));
|
|
72
|
-
};
|
|
73
|
-
function extractSchoolsWithDepartments({ organisationer, organisationskopplingar, language, deprecated = false, }) {
|
|
74
|
-
const schoolCodes = getSchoolCodes(deprecated);
|
|
75
|
-
const schoolOrganisations = organisationer.filter(organisation => schoolCodes.includes(organisation.Organisationskod));
|
|
76
|
-
const schoolsWithDepartments = schoolOrganisations.map(school => {
|
|
77
|
-
const departmentHierarchy = getSubDepartments({
|
|
78
|
-
uid: school.Uid,
|
|
79
|
-
organisationskopplingar,
|
|
80
|
-
organisationer,
|
|
81
|
-
language,
|
|
82
|
-
});
|
|
83
|
-
const allDepartments = departmentHierarchy.flatMap(flattenDepartment);
|
|
84
|
-
// This filters out departments like "9A"
|
|
85
|
-
const departments = allDepartments.filter(department => department.code.startsWith(school.Organisationskod));
|
|
86
|
-
departments.sort((a, b) => a.code.localeCompare(b.code));
|
|
87
|
-
const departmentsToShow = filterDepartments(departments, deprecated);
|
|
88
|
-
return {
|
|
89
|
-
departmentPrefix: school.Organisationskod,
|
|
90
|
-
name: getSchoolNameFromLadokOrganisation(school, language),
|
|
91
|
-
departments: departmentsToShow,
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
schoolsWithDepartments.sort((a, b) => a.departmentPrefix.localeCompare(b.departmentPrefix));
|
|
95
|
-
return schoolsWithDepartments;
|
|
96
|
-
}
|
|
97
|
-
const getSubDepartments = ({ uid, organisationskopplingar, organisationer, language, }) => {
|
|
98
|
-
const matchingDepartmentKopplingar = organisationskopplingar.filter(koppling => koppling.OverliggandeRef.Uid === uid);
|
|
99
|
-
const matchingDepartments = matchingDepartmentKopplingar
|
|
100
|
-
.map(koppling => {
|
|
101
|
-
var _a;
|
|
102
|
-
const department = organisationer.find(org => org.Uid === koppling.UnderliggandeRef.Uid);
|
|
103
|
-
if (!department || !isCurrentDepartment(department))
|
|
104
|
-
return null;
|
|
105
|
-
const name = getDepartmentNameFromLadokOrganisation(department, language);
|
|
106
|
-
return {
|
|
107
|
-
name,
|
|
108
|
-
code: (_a = department.Organisationskod) !== null && _a !== void 0 ? _a : '',
|
|
109
|
-
departments: getSubDepartments({ uid: department.Uid, organisationskopplingar, organisationer, language }),
|
|
110
|
-
};
|
|
111
|
-
})
|
|
112
|
-
.filter(department => department !== null);
|
|
113
|
-
return matchingDepartments;
|
|
114
|
-
};
|
|
115
|
-
const isCurrentDepartment = (organisation) => {
|
|
116
|
-
var _a, _b;
|
|
117
|
-
return !((_a = organisation.Giltighetsperiod) === null || _a === void 0 ? void 0 : _a.Slutdatum) || new Date((_b = organisation.Giltighetsperiod) === null || _b === void 0 ? void 0 : _b.Slutdatum) > new Date();
|
|
118
|
-
};
|
|
119
|
-
const getSchoolNameFromLadokOrganisation = (org, language) => {
|
|
120
|
-
var _a;
|
|
121
|
-
let name = (_a = org.Benamning[language].split('/')[1]) !== null && _a !== void 0 ? _a : org.Benamning.sv;
|
|
122
|
-
name = name.replace('Skolan för ', '');
|
|
123
|
-
name = `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
124
|
-
return name;
|
|
125
|
-
};
|
|
126
|
-
const getDepartmentNameFromLadokOrganisation = (org, language) => {
|
|
127
|
-
var _a;
|
|
128
|
-
let name = (_a = org.Benamning[language].split('/')[1]) !== null && _a !== void 0 ? _a : org.Benamning.sv;
|
|
129
|
-
return name;
|
|
130
|
-
};
|
|
131
|
-
const flattenDepartment = ({ name, code, departments }) => {
|
|
132
|
-
if (departments.length === 0) {
|
|
133
|
-
return [{ code, name }];
|
|
134
|
-
}
|
|
135
|
-
return [{ code, name }, ...departments.flatMap(flattenDepartment)];
|
|
136
|
-
};
|
|
137
33
|
//# sourceMappingURL=createSupportApis.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSupportApis.js","sourceRoot":"","sources":["../../src/supportApis/createSupportApis.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"createSupportApis.js","sourceRoot":"","sources":["../../src/supportApis/createSupportApis.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,+DAA2D;AAC3D,qDAAiD;AAW1C,MAAM,gBAAgB,GAAG,CAAC,WAAsC,EAAc,EAAE;IACrF,MAAM,mBAAmB,GAAG,IAAI,yCAAmB,CAAC,WAAW,CAAC,CAAA;IAChE,MAAM,cAAc,GAAG,IAAI,+BAAc,CAAC,WAAW,CAAC,CAAA;IACtD,OAAO;QACL,oBAAoB,EAAE,cAAc,CAAC,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC;QAC9E,gEAAgE,EAAE,KAI/D,EAAE,4CAJoE,EACvE,IAAI,EAAE,QAAQ,EACd,sCAAsC,GAAG,KAAK,EAC9C,cAAc,GAAG,KAAK,GACvB;YACC,MAAM,EAAE,cAAc,EAAE,uBAAuB,EAAE,GAAG,MAAM,mBAAmB,CAAC,mBAAmB,EAAE,CAAA;YAEnG,OAAO,cAAc,CAAC,gEAAgE,CAAC;gBACrF,cAAc;gBACd,uBAAuB;gBACvB,QAAQ;gBACR,sCAAsC;gBACtC,cAAc;aACf,CAAC,CAAA;QACJ,CAAC,CAAA;KACF,CAAA;AACH,CAAC,CAAA;AArBY,QAAA,gBAAgB,oBAqB5B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { LadokMellanlagerApiClient, Organisation, Organisationskoppling } from '@kth/ladok-mellanlager-client';
|
|
2
|
+
export type OrganisationData = {
|
|
3
|
+
organisationer: Organisation[];
|
|
4
|
+
organisationskopplingar: Organisationskoppling[];
|
|
5
|
+
};
|
|
6
|
+
export declare class OrganisationService {
|
|
7
|
+
private ladokClient;
|
|
8
|
+
private static cache;
|
|
9
|
+
constructor(ladokClient: LadokMellanlagerApiClient);
|
|
10
|
+
private aggregateOrganisationData;
|
|
11
|
+
getOrganisationData(): Promise<OrganisationData>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.OrganisationService = void 0;
|
|
13
|
+
const cache_1 = require("../cache");
|
|
14
|
+
const cacheTTLInMinutes = 60;
|
|
15
|
+
class OrganisationService {
|
|
16
|
+
constructor(ladokClient) {
|
|
17
|
+
this.ladokClient = ladokClient;
|
|
18
|
+
}
|
|
19
|
+
aggregateOrganisationData() {
|
|
20
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
+
var _a, _b, _c, _d;
|
|
22
|
+
const [organisationskopplingsResponse, organisationsResponse] = yield Promise.all([
|
|
23
|
+
this.ladokClient.organisationskoppling(),
|
|
24
|
+
this.ladokClient.organisation(),
|
|
25
|
+
]);
|
|
26
|
+
const organisationer = (_b = (_a = organisationsResponse.data) === null || _a === void 0 ? void 0 : _a.Organisationer) !== null && _b !== void 0 ? _b : [];
|
|
27
|
+
const organisationskopplingar = (_d = (_c = organisationskopplingsResponse.data) === null || _c === void 0 ? void 0 : _c.Organisationskopplingar) !== null && _d !== void 0 ? _d : [];
|
|
28
|
+
return {
|
|
29
|
+
organisationer,
|
|
30
|
+
organisationskopplingar,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
getOrganisationData() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return OrganisationService.cache.getData('organisationData', () => this.aggregateOrganisationData());
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.OrganisationService = OrganisationService;
|
|
41
|
+
OrganisationService.cache = new cache_1.Cache(cacheTTLInMinutes);
|
|
42
|
+
//# sourceMappingURL=organisationService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organisationService.js","sourceRoot":"","sources":["../../src/supportApis/organisationService.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAgC;AAOhC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAE5B,MAAa,mBAAmB;IAE9B,YAAoB,WAAsC;QAAtC,gBAAW,GAAX,WAAW,CAA2B;IAAG,CAAC;IAEhD,yBAAyB;;;YACrC,MAAM,CAAC,8BAA8B,EAAE,qBAAqB,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;gBAChF,IAAI,CAAC,WAAW,CAAC,qBAAqB,EAAE;gBACxC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE;aAChC,CAAC,CAAA;YAEF,MAAM,cAAc,GAAG,MAAA,MAAA,qBAAqB,CAAC,IAAI,0CAAE,cAAc,mCAAI,EAAE,CAAA;YACvE,MAAM,uBAAuB,GAAG,MAAA,MAAA,8BAA8B,CAAC,IAAI,0CAAE,uBAAuB,mCAAI,EAAE,CAAA;YAElG,OAAO;gBACL,cAAc;gBACd,uBAAuB;aACxB,CAAA;QACH,CAAC;KAAA;IAEY,mBAAmB;;YAC9B,OAAO,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC,CAAA;QACtG,CAAC;KAAA;;AArBH,kDAsBC;AArBgB,yBAAK,GAA4B,IAAI,aAAK,CAAmB,iBAAiB,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Organisation, Organisationskoppling } from '@kth/ladok-mellanlager-client';
|
|
2
|
+
import { Language } from '../utils';
|
|
3
|
+
import { DepartmentFlat } from './types';
|
|
4
|
+
export declare function extractSchoolsWithDepartments({ organisationer, organisationskopplingar, language, deprecated, }: {
|
|
5
|
+
organisationer: Organisation[];
|
|
6
|
+
organisationskopplingar: Organisationskoppling[];
|
|
7
|
+
language: Language;
|
|
8
|
+
deprecated: boolean;
|
|
9
|
+
}): {
|
|
10
|
+
departmentPrefix: string;
|
|
11
|
+
name: string;
|
|
12
|
+
departments: DepartmentFlat[];
|
|
13
|
+
}[];
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractSchoolsWithDepartments = extractSchoolsWithDepartments;
|
|
4
|
+
const supportUtils_1 = require("./supportUtils");
|
|
5
|
+
const currentSchoolCodes = ['A', 'B', 'C', 'J', 'M', 'S', 'U'];
|
|
6
|
+
const deprecatedSchoolCodes = ['D', 'K', 'H', 'L'];
|
|
7
|
+
const deprecatedOrganisationCodesToInclude = ['DM', 'KD', 'KE', 'KF', 'HA', 'HPN', 'LA', 'LPA'];
|
|
8
|
+
const currentOrganisationCodesToExclude = [
|
|
9
|
+
'AA',
|
|
10
|
+
'AD',
|
|
11
|
+
'ADA',
|
|
12
|
+
'AG',
|
|
13
|
+
'AGA',
|
|
14
|
+
'AI',
|
|
15
|
+
'AIA',
|
|
16
|
+
'AK',
|
|
17
|
+
'AKA',
|
|
18
|
+
'ALA',
|
|
19
|
+
'AM',
|
|
20
|
+
'CA',
|
|
21
|
+
'CBA',
|
|
22
|
+
'CBB',
|
|
23
|
+
'JA',
|
|
24
|
+
'MA',
|
|
25
|
+
'MAD',
|
|
26
|
+
'MAS',
|
|
27
|
+
'MFE',
|
|
28
|
+
'MK',
|
|
29
|
+
'SAC',
|
|
30
|
+
'UTHS',
|
|
31
|
+
'LA',
|
|
32
|
+
]; // TODO This is a list of organisationCodes that has neither current nor cancelled courses. We have to find a better way to do this.
|
|
33
|
+
const getSchoolCodes = (deprecated) => {
|
|
34
|
+
if (deprecated)
|
|
35
|
+
return deprecatedSchoolCodes;
|
|
36
|
+
return currentSchoolCodes;
|
|
37
|
+
};
|
|
38
|
+
const filterDepartments = (departments, deprecated) => {
|
|
39
|
+
if (deprecated) {
|
|
40
|
+
return departments.filter(department => deprecatedOrganisationCodesToInclude.includes(department.code));
|
|
41
|
+
}
|
|
42
|
+
return departments.filter(department => currentOrganisationCodesToExclude.every(code => department.code !== code));
|
|
43
|
+
};
|
|
44
|
+
function extractSchoolsWithDepartments({ organisationer, organisationskopplingar, language, deprecated = false, }) {
|
|
45
|
+
const schoolCodes = getSchoolCodes(deprecated);
|
|
46
|
+
const schoolOrganisations = organisationer.filter(organisation => schoolCodes.includes(organisation.Organisationskod));
|
|
47
|
+
const schoolsWithDepartments = schoolOrganisations.map(school => {
|
|
48
|
+
const departmentHierarchy = (0, supportUtils_1.getSubDepartments)({
|
|
49
|
+
uid: school.Uid,
|
|
50
|
+
organisationskopplingar,
|
|
51
|
+
organisationer,
|
|
52
|
+
language,
|
|
53
|
+
});
|
|
54
|
+
const allDepartments = departmentHierarchy.flatMap(supportUtils_1.flattenDepartment);
|
|
55
|
+
// This filters out departments like "9A"
|
|
56
|
+
const departments = allDepartments.filter(department => department.code.startsWith(school.Organisationskod));
|
|
57
|
+
departments.sort((a, b) => a.code.localeCompare(b.code));
|
|
58
|
+
const departmentsToShow = filterDepartments(departments, deprecated);
|
|
59
|
+
return {
|
|
60
|
+
departmentPrefix: school.Organisationskod,
|
|
61
|
+
name: (0, supportUtils_1.getSchoolNameFromLadokOrganisation)(school, language),
|
|
62
|
+
departments: departmentsToShow,
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
schoolsWithDepartments.sort((a, b) => a.departmentPrefix.localeCompare(b.departmentPrefix));
|
|
66
|
+
return schoolsWithDepartments;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=searchSupportUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"searchSupportUtil.js","sourceRoot":"","sources":["../../src/supportApis/searchSupportUtil.ts"],"names":[],"mappings":";;AA+CA,sEAyCC;AAtFD,iDAAyG;AAGzG,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAC9D,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAElD,MAAM,oCAAoC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;AAC/F,MAA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B,GAAG,IAAA,gCAAiB,EAAC;YAC5C,GAAG,EAAE,MAAM,CAAC,GAAG;YACf,uBAAuB;YACvB,cAAc;YACd,QAAQ;SACT,CAAC,CAAA;QAEF,MAAM,cAAc,GAAqB,mBAAmB,CAAC,OAAO,CAAC,gCAAiB,CAAC,CAAA;QAEvF,yCAAyC;QACzC,MAAM,WAAW,GAAG,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAA;QAE5G,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAExD,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QAEpE,OAAO;YACL,gBAAgB,EAAE,MAAM,CAAC,gBAAgB;YACzC,IAAI,EAAE,IAAA,iDAAkC,EAAC,MAAM,EAAE,QAAQ,CAAC;YAC1D,WAAW,EAAE,iBAAiB;SAC/B,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAA;IAC3F,OAAO,sBAAsB,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LadokMellanlagerApiClient } from '@kth/ladok-mellanlager-client';
|
|
2
|
+
import { Language } from '../utils';
|
|
3
|
+
import { DepartmentFlat, SchoolWithDepartments } from './types';
|
|
4
|
+
export declare class SupportService {
|
|
5
|
+
private ladokClient;
|
|
6
|
+
private static cache;
|
|
7
|
+
private organisationService;
|
|
8
|
+
constructor(ladokClient: LadokMellanlagerApiClient);
|
|
9
|
+
getCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse(args: Parameters<SupportService['aggregateCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse']>[0]): ReturnType<SupportService['aggregateCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse']>;
|
|
10
|
+
private aggregateCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse;
|
|
11
|
+
private hasAtLeastOneCourse;
|
|
12
|
+
private hasItems;
|
|
13
|
+
private createQuery;
|
|
14
|
+
getSchoolsWithDepartmentsForSearch(language: Language): Promise<SchoolWithDepartments[]>;
|
|
15
|
+
getFlatDepartmentListForSearch(language: Language): Promise<DepartmentFlat[]>;
|
|
16
|
+
getDepartmentByCode(departmentCode: string, language: Language): Promise<DepartmentFlat | undefined>;
|
|
17
|
+
createDepartmentList(language: Language, deprecated?: boolean): Promise<SchoolWithDepartments[]>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SupportService = void 0;
|
|
13
|
+
const ladok_attributvarde_utils_1 = require("@kth/ladok-attributvarde-utils");
|
|
14
|
+
const educationalTypeUtils_1 = require("../search/utils/educationalTypeUtils");
|
|
15
|
+
const typeChecking_1 = require("../utils/typeChecking");
|
|
16
|
+
const supportUtils_1 = require("./supportUtils");
|
|
17
|
+
const cache_1 = require("../cache");
|
|
18
|
+
const organisationService_1 = require("./organisationService");
|
|
19
|
+
const searchSupportUtil_1 = require("./searchSupportUtil");
|
|
20
|
+
const currentSchoolCodes = ['A', 'C', 'J', 'M', 'S', 'U'];
|
|
21
|
+
const deprecatedSchoolCodes = ['B', 'D', 'E', 'H', 'I', 'K', 'L'];
|
|
22
|
+
const cacheTTLInMinutes = 60;
|
|
23
|
+
const createCacheKey = (language, includeDepartmentsWithCancelledCourses, onlyThirdCycle) => `schoolsWithDepartments-${language}-${includeDepartmentsWithCancelledCourses}-${onlyThirdCycle}`;
|
|
24
|
+
class SupportService {
|
|
25
|
+
constructor(ladokClient) {
|
|
26
|
+
this.ladokClient = ladokClient;
|
|
27
|
+
this.organisationService = new organisationService_1.OrganisationService(ladokClient);
|
|
28
|
+
}
|
|
29
|
+
getCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse(args) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const { language, includeDepartmentsWithCancelledCourses = false, onlyThirdCycle = false } = args;
|
|
32
|
+
return SupportService.cache.getData(createCacheKey(language, includeDepartmentsWithCancelledCourses, onlyThirdCycle), () => this.aggregateCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse(args));
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
aggregateCurrentAndDeprecatedSchoolsAndDepartmentsWithAtLeastOneCourse(_a) {
|
|
36
|
+
return __awaiter(this, arguments, void 0, function* ({ organisationer, organisationskopplingar, language, onlyThirdCycle = false, includeDepartmentsWithCancelledCourses = false, }) {
|
|
37
|
+
if (!organisationer.length || !organisationskopplingar.length) {
|
|
38
|
+
return Promise.resolve({ current: [], deprecated: [] });
|
|
39
|
+
}
|
|
40
|
+
const schoolsWithDepartments = (0, supportUtils_1.getSchoolsWithDepartments)({
|
|
41
|
+
organisationer,
|
|
42
|
+
schoolCodes: [...currentSchoolCodes, ...deprecatedSchoolCodes],
|
|
43
|
+
organisationskopplingar,
|
|
44
|
+
language,
|
|
45
|
+
});
|
|
46
|
+
const departments = schoolsWithDepartments.flatMap(({ departments }) => departments.flat());
|
|
47
|
+
const departmentCodesWithCourses = (yield Promise.all(departments.map((_a) => __awaiter(this, [_a], void 0, function* ({ code }) {
|
|
48
|
+
const hasCourses = yield this.hasAtLeastOneCourse(code, includeDepartmentsWithCancelledCourses, onlyThirdCycle);
|
|
49
|
+
return hasCourses ? code : null;
|
|
50
|
+
})))).filter(typeChecking_1.isDefined);
|
|
51
|
+
const schoolsWithDepartmentsFiltered = (0, supportUtils_1.filterOutDepartmentsWithoutCourses)(schoolsWithDepartments, departmentCodesWithCourses);
|
|
52
|
+
const current = schoolsWithDepartmentsFiltered.filter(school => currentSchoolCodes.includes(school.departmentPrefix));
|
|
53
|
+
const deprecated = schoolsWithDepartmentsFiltered.filter(school => deprecatedSchoolCodes.includes(school.departmentPrefix));
|
|
54
|
+
return Promise.resolve({ current, deprecated });
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
hasAtLeastOneCourse(departmentCode, includeCancelledCourses, onlyThirdCycle) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const utbildningsniva = onlyThirdCycle ? [ladok_attributvarde_utils_1.EducationalLevelCode.Research] : undefined;
|
|
60
|
+
const queries = [this.createQuery(departmentCode, utbildningsniva, false)];
|
|
61
|
+
if (includeCancelledCourses) {
|
|
62
|
+
queries.push(this.createQuery(departmentCode, utbildningsniva, true));
|
|
63
|
+
}
|
|
64
|
+
const result = yield Promise.all(queries.map(query => this.ladokClient.sokUtbildningsInstansSlim(query)));
|
|
65
|
+
return result.some(res => this.hasItems(res));
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
hasItems(response) {
|
|
69
|
+
return (0, typeChecking_1.isDefined)(response.items) && response.items.length > 0;
|
|
70
|
+
}
|
|
71
|
+
createQuery(departmentCode, utbildningsniva, avvecklad) {
|
|
72
|
+
return {
|
|
73
|
+
utbildningstypgrundtyp: 'KURS',
|
|
74
|
+
kodEllerBenamning: '*',
|
|
75
|
+
organisation: departmentCode,
|
|
76
|
+
senasteversion: 'true',
|
|
77
|
+
utbildningstypid: (0, educationalTypeUtils_1.getUtbildningsnivaParameterForKursInstans)(utbildningsniva),
|
|
78
|
+
avvecklad: avvecklad ? 'true' : 'false',
|
|
79
|
+
antalTraffar: '1',
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
getSchoolsWithDepartmentsForSearch(language) {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
+
const [currentDepartmentList, deprecatedDepartmentList] = yield Promise.all([
|
|
85
|
+
this.createDepartmentList(language),
|
|
86
|
+
this.createDepartmentList(language, true),
|
|
87
|
+
]);
|
|
88
|
+
const departmentList = [...currentDepartmentList, ...deprecatedDepartmentList];
|
|
89
|
+
return departmentList;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
getFlatDepartmentListForSearch(language) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const schoolsWithDepartments = yield this.getSchoolsWithDepartmentsForSearch(language);
|
|
95
|
+
const flatDepartmentList = (0, supportUtils_1.extractDepartmentFlatsFromSchoolsWithDepartments)(schoolsWithDepartments);
|
|
96
|
+
return flatDepartmentList;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
getDepartmentByCode(departmentCode, language) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const flatDepartmentList = yield this.getFlatDepartmentListForSearch(language);
|
|
102
|
+
const department = flatDepartmentList.find(department => department.code === departmentCode);
|
|
103
|
+
return department;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
createDepartmentList(language_1) {
|
|
107
|
+
return __awaiter(this, arguments, void 0, function* (language, deprecated = false) {
|
|
108
|
+
const { organisationer, organisationskopplingar } = yield this.organisationService.getOrganisationData();
|
|
109
|
+
const schoolsWithDepartments = (0, searchSupportUtil_1.extractSchoolsWithDepartments)({
|
|
110
|
+
organisationer,
|
|
111
|
+
organisationskopplingar,
|
|
112
|
+
language,
|
|
113
|
+
deprecated,
|
|
114
|
+
});
|
|
115
|
+
return schoolsWithDepartments;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.SupportService = SupportService;
|
|
120
|
+
SupportService.cache = new cache_1.Cache(cacheTTLInMinutes);
|
|
121
|
+
//# sourceMappingURL=supportService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supportService.js","sourceRoot":"","sources":["../../src/supportApis/supportService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8EAAqE;AASrE,+EAAgG;AAChG,wDAAiD;AAEjD,iDAIuB;AACvB,oCAAgC;AAEhC,+DAA2D;AAC3D,2DAAmE;AAEnE,MAAM,kBAAkB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACzD,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AAEjE,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAI5B,MAAM,cAAc,GAAG,CAAC,QAAkB,EAAE,sCAA+C,EAAE,cAAuB,EAAE,EAAE,CACtH,0BAA0B,QAAQ,IAAI,sCAAsC,IAAI,cAAc,EAAE,CAAA;AAElG,MAAa,cAAc;IAIzB,YAAoB,WAAsC;QAAtC,gBAAW,GAAX,WAAW,CAA2B;QACxD,IAAI,CAAC,mBAAmB,GAAG,IAAI,yCAAmB,CAAC,WAAW,CAAC,CAAA;IACjE,CAAC;IAEY,gEAAgE,CAC3E,IAA6G;;YAE7G,MAAM,EAAE,QAAQ,EAAE,s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AAU,CAAC,IAAI,KAAK,cAAc,CAAC,CAAA;YAC5F,OAAO,UAAU,CAAA;QACnB,CAAC;KAAA;IAEY,oBAAoB;6DAAC,QAAkB,EAAE,UAAU,GAAG,KAAK;YACtE,MAAM,EAAE,cAAc,EAAE,uBAAuB,EAAE,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,CAAA;YAExG,MAAM,sBAAsB,GAAG,IAAA,iDAA6B,EAAC;gBAC3D,cAAc;gBACd,uBAAuB;gBACvB,QAAQ;gBACR,UAAU;aACX,CAAC,CAAA;YAEF,OAAO,sBAAsB,CAAA;QAC/B,CAAC;KAAA;;AA1IH,wCA2IC;AA1IgB,oBAAK,GAAqC,IAAI,aAAK,CAA4B,iBAAiB,CAAC,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Organisationskoppling } from '@kth/ladok-mellanlager-client/dist/types/endpoints/organisationskoppling';
|
|
2
|
+
import { Language } from '../utils';
|
|
3
|
+
import { Organisation } from '@kth/ladok-mellanlager-client/dist/types/endpoints/organisation';
|
|
4
|
+
import { Department, DepartmentFlat, SchoolWithDepartments } from './types';
|
|
5
|
+
/**
|
|
6
|
+
* Retrieves the sub-departments for a given organisation (typically a school) by traversing the organisation hierarchy.
|
|
7
|
+
*
|
|
8
|
+
* This function recursively finds all departments under the specified organisation UID, optionally filtering out deprecated departments.
|
|
9
|
+
* Each department is represented as a hierarchical tree structure, where each node contains its name, code, and any sub-departments.
|
|
10
|
+
*
|
|
11
|
+
* @param params - The parameters for retrieving sub-departments.
|
|
12
|
+
* @param params.uid - The UID of the parent organisation (e.g., a school).
|
|
13
|
+
* @param params.organisationskopplingar - Array of organisation connection objects describing the hierarchy.
|
|
14
|
+
* @param params.organisationer - Array of organisation objects.
|
|
15
|
+
* @param params.language - The language to use for department names.
|
|
16
|
+
* @param params.includeDeprecatedDepartments - If true, include deprecated departments; otherwise, only include current departments. Defaults to false.
|
|
17
|
+
* @returns An array of Department objects representing the hierarchical structure of sub-departments.
|
|
18
|
+
*
|
|
19
|
+
* @see handleSchools (in coursesByOrgUtil.ts) for usage in filtering schools and departments with courses.
|
|
20
|
+
* @see extractSchoolsWithDepartments (in createSupportApis.ts) for usage in building school/department lists.
|
|
21
|
+
*/
|
|
22
|
+
export declare const getSubDepartments: ({ uid, organisationskopplingar, organisationer, language, includeDeprecatedDepartments, }: {
|
|
23
|
+
uid: string;
|
|
24
|
+
organisationskopplingar: Organisationskoppling[];
|
|
25
|
+
organisationer: Organisation[];
|
|
26
|
+
language: Language;
|
|
27
|
+
includeDeprecatedDepartments?: boolean;
|
|
28
|
+
}) => Department[];
|
|
29
|
+
export declare const flattenDepartment: ({ name, code, departments }: Department) => DepartmentFlat[];
|
|
30
|
+
export declare const getSchoolNameFromLadokOrganisation: (org: Organisation, language: Language) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves a list of schools and their associated departments based on provided organisation data and school codes.
|
|
33
|
+
*
|
|
34
|
+
* This function filters the given organisations to include only those matching the specified school codes,
|
|
35
|
+
* then constructs a list of schools, each with its departments. Departments are determined by traversing the
|
|
36
|
+
* organisation hierarchy and flattening the department structure. Only departments whose codes start with the
|
|
37
|
+
* school's code are included.
|
|
38
|
+
*
|
|
39
|
+
* @param organisationer - Array of organisation objects representing schools and departments.
|
|
40
|
+
* @param organisationskopplingar - Array of organisation connection objects describing the hierarchy.
|
|
41
|
+
* @param language - The language to use for school and department names.
|
|
42
|
+
* @param schoolCodes - Array of school codes to include in the result.
|
|
43
|
+
* @returns An array of objects, each representing a school with its code, name, and filtered departments.
|
|
44
|
+
*/
|
|
45
|
+
export declare const getSchoolsWithDepartments: ({ organisationer, organisationskopplingar, language, schoolCodes, }: {
|
|
46
|
+
organisationer: Organisation[];
|
|
47
|
+
schoolCodes: string[];
|
|
48
|
+
organisationskopplingar: Organisationskoppling[];
|
|
49
|
+
language: Language;
|
|
50
|
+
}) => {
|
|
51
|
+
departmentPrefix: string;
|
|
52
|
+
name: string;
|
|
53
|
+
departments: DepartmentFlat[];
|
|
54
|
+
}[];
|
|
55
|
+
export declare const filterOutDepartmentsWithoutCourses: (departments: SchoolWithDepartments[], departmentCodesWithCourses: string[]) => SchoolWithDepartments[];
|
|
56
|
+
export declare const extractDepartmentFlatsFromSchoolsWithDepartments: (schoolsWithDepartments: {
|
|
57
|
+
departmentPrefix: string;
|
|
58
|
+
name: string;
|
|
59
|
+
departments: DepartmentFlat[];
|
|
60
|
+
}[]) => DepartmentFlat[];
|