Total Complexity | 9 |
Complexity/F | 4.5 |
Lines of Code | 66 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {Event, EventType} from './Event.entity'; |
||
2 | import {IEventsOverview} from './IEventsOverview'; |
||
3 | |||
4 | export class GetEventsOverview { |
||
5 | public index(events: Event[]): IEventsOverview { |
||
6 | const eventsByDate = []; |
||
7 | const overview: IEventsOverview = { |
||
8 | mission: 0, |
||
9 | dojo: 0, |
||
10 | formationConference: 0, |
||
11 | holiday: 0, |
||
12 | medicalLeave: 0, |
||
13 | support: 0, |
||
14 | workFree: 0, |
||
15 | other: 0, |
||
16 | mealTicket: 0 |
||
17 | }; |
||
18 | |||
19 | for (const event of events) { |
||
20 | const dayIndex = new Date(event.getDate()).getDate() - 1; |
||
21 | const time = event.getTime() / 100; |
||
22 | const type = event.getType(); |
||
23 | |||
24 | if (eventsByDate[dayIndex]) { |
||
25 | eventsByDate[dayIndex].push({time, type}); |
||
26 | } else { |
||
27 | eventsByDate[dayIndex] = [{time, type}]; |
||
28 | } |
||
29 | |||
30 | overview[event.getType()] += time; |
||
31 | } |
||
32 | |||
33 | return this.calculateNumberOfMealTicket(overview, eventsByDate); |
||
34 | } |
||
35 | |||
36 | public calculateNumberOfMealTicket( |
||
37 | overview: IEventsOverview, |
||
38 | eventsByDate: any[] |
||
39 | ): IEventsOverview { |
||
40 | for (const sortedEvent of eventsByDate) { |
||
41 | if (!sortedEvent) { |
||
42 | continue; |
||
43 | } |
||
44 | |||
45 | let totalPerDay = 0; |
||
46 | |||
47 | for (const {time, type} of sortedEvent) { |
||
48 | if ( |
||
49 | type !== EventType.WORK_FREE && |
||
50 | type !== EventType.MEDICAL_LEAVE && |
||
51 | type !== EventType.HOLIDAY && |
||
52 | type !== EventType.OTHER |
||
53 | ) { |
||
54 | totalPerDay += time; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | if (totalPerDay > 0.5) { |
||
59 | overview.mealTicket++; |
||
60 | } |
||
61 | } |
||
62 | |||
63 | return overview; |
||
64 | } |
||
65 | } |
||
66 |