1
1
import { getCsrfToken } from '@/adapter/util/Csrf' ;
2
2
import type { EventRepository } from '@/application' ;
3
+ import { DateUtils } from '@/common' ;
3
4
import type { Event , EventKey , EventState , ImportError , PositionKey , UserKey } from '@/domain' ;
4
5
import { EventType , SlotCriticality } from '@/domain' ;
5
6
@@ -72,9 +73,9 @@ interface ImportErrorRepresentation {
72
73
73
74
export class EventRestRepository implements EventRepository {
74
75
public static mapEventToDomain ( eventRepresentation : EventRepresentation ) : Event {
75
- return {
76
+ const event : Event = {
76
77
key : eventRepresentation . key ,
77
- type : EventType . VOYAGE ,
78
+ type : EventType . MultiDayEvent ,
78
79
name : eventRepresentation . name ,
79
80
description : eventRepresentation . description ,
80
81
state : eventRepresentation . state as EventState ,
@@ -99,6 +100,22 @@ export class EventRestRepository implements EventRepository {
99
100
} ) ) ,
100
101
assignedUserCount : eventRepresentation . registrations . filter ( ( it ) => it . slotKey ) . length ,
101
102
} ;
103
+ event . type = EventRestRepository . mapEventType ( event ) ;
104
+ return event ;
105
+ }
106
+
107
+ private static mapEventType ( event : Event ) : EventType {
108
+ const start = DateUtils . cropToPrecision ( event . start , 'days' ) ;
109
+ const end = DateUtils . cropToPrecision ( event . end , 'days' ) ;
110
+ const durationDays = new Date ( event . end . getTime ( ) - event . start . getTime ( ) ) . getDate ( ) ;
111
+
112
+ if ( start . getTime ( ) === end . getTime ( ) ) {
113
+ return EventType . SingleDayEvent ;
114
+ }
115
+ if ( durationDays <= 3 ) {
116
+ return EventType . WeekendEvent ;
117
+ }
118
+ return EventType . MultiDayEvent ;
102
119
}
103
120
104
121
public async findAll ( year : number ) : Promise < Event [ ] > {
0 commit comments