@@ -31,6 +31,38 @@ interface BatchCoursePreviewParameters {
3131 days : number ;
3232}
3333
34+ function normalizeCourseEditions (
35+ response : Record < string , UsosCourseEdition [ ] > ,
36+ ) : Record < string , CoursePreviewDTO [ ] > {
37+ const normalizedData : Record < string , CoursePreviewDTO [ ] > = { } ;
38+
39+ for ( const [ editionId , events ] of Object . entries ( response ) ) {
40+ if ( ! Array . isArray ( events ) ) {
41+ continue ;
42+ }
43+
44+ const mapped = events . map ( ( event ) => ( {
45+ id : editionId ,
46+ startTime : event . start_time ?? "" ,
47+ endTime : event . end_time ?? "" ,
48+ name : event . name ?. pl ?? event . name ?. en ?? "" ,
49+ type : event . type ?? "" ,
50+ groupNumber : event . group_number ?? "" ,
51+ lecturerIds : event . lecturer_ids ?? [ ] ,
52+ classTypeName : event . classtype_name ?. pl ?? event . classtype_name ?. en ?? "" ,
53+ } ) ) ;
54+
55+ mapped . sort (
56+ ( a , b ) =>
57+ new Date ( a . startTime ) . getTime ( ) - new Date ( b . startTime ) . getTime ( ) ,
58+ ) ;
59+
60+ normalizedData [ editionId ] = mapped ;
61+ }
62+
63+ return normalizedData ;
64+ }
65+
3466export async function getBatchCoursePreviewAction (
3567 parameters : BatchCoursePreviewParameters ,
3668) : Promise < Record < string , CoursePreviewDTO [ ] > > {
@@ -63,38 +95,7 @@ export async function getBatchCoursePreviewAction(
6395 } ,
6496 ) ;
6597
66- if ( response == null ) {
67- return { } ;
68- }
69-
70- const normalizedData : Record < string , CoursePreviewDTO [ ] > = { } ;
71-
72- for ( const [ editionId , events ] of Object . entries ( response ) ) {
73- if ( ! Array . isArray ( events ) ) {
74- continue ;
75- }
76-
77- const mapped = events . map ( ( event ) => ( {
78- id : editionId ,
79- startTime : event . start_time ?? "" ,
80- endTime : event . end_time ?? "" ,
81- name : event . name ?. pl ?? event . name ?. en ?? "" ,
82- type : event . type ?? "" ,
83- groupNumber : event . group_number ?? "" ,
84- lecturerIds : event . lecturer_ids ?? [ ] ,
85- classTypeName :
86- event . classtype_name ?. pl ?? event . classtype_name ?. en ?? "" ,
87- } ) ) ;
88-
89- mapped . sort (
90- ( a , b ) =>
91- new Date ( a . startTime ) . getTime ( ) - new Date ( b . startTime ) . getTime ( ) ,
92- ) ;
93-
94- normalizedData [ editionId ] = mapped ;
95- }
96-
97- return normalizedData ;
98+ return normalizeCourseEditions ( response ) ;
9899 } ,
99100 } ) ;
100101}
0 commit comments