Total Complexity | 4 |
Complexity/F | 4 |
Lines of Code | 39 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
2 | import { FairCalendarView } from 'src/Application/FairCalendar/View/FairCalendarView'; |
||
3 | import { CooperativeNotFoundException } from '../Settings/Repository/CooperativeNotFoundException'; |
||
4 | import { ICooperativeRepository } from '../Settings/Repository/ICooperativeRepository'; |
||
5 | import { ICalendarOverview } from './ICalendarOverview'; |
||
6 | |||
7 | export class GetFairCalendarOverview { |
||
8 | constructor( |
||
9 | @Inject('ICooperativeRepository') |
||
10 | private readonly cooperativeRepository: ICooperativeRepository |
||
11 | ) {} |
||
12 | |||
13 | public async index(items: FairCalendarView[]): Promise<ICalendarOverview> { |
||
14 | const cooperative = await this.cooperativeRepository.find(); |
||
15 | if (!cooperative) { |
||
16 | throw new CooperativeNotFoundException(); |
||
17 | } |
||
18 | |||
19 | const overviewInDays: ICalendarOverview = { |
||
20 | mission: 0, |
||
21 | dojo: 0, |
||
22 | formationConference: 0, |
||
23 | leave: 0, |
||
24 | support: 0, |
||
25 | other: 0 |
||
26 | }; |
||
27 | |||
28 | for (const { time, type: itemType } of items) { |
||
29 | const type = itemType.startsWith('leave_') ? 'leave' : itemType; |
||
30 | const days = time / cooperative.getDayDuration(); |
||
31 | |||
32 | overviewInDays[type] = |
||
33 | Math.round((overviewInDays[type] + days) * 100) / 100; |
||
34 | } |
||
35 | |||
36 | return overviewInDays; |
||
37 | } |
||
38 | } |
||
39 |