Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 38 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Inject, Injectable } from '@nestjs/common'; |
||
2 | import { RowFactory } from 'src/Infrastructure/Tables/RowFactory'; |
||
3 | import { Table } from 'src/Infrastructure/Tables'; |
||
4 | import { ICalendarOverview } from 'src/Domain/FairCalendar/ICalendarOverview'; |
||
5 | import { EventType } from 'src/Domain/FairCalendar/Event.entity'; |
||
6 | import { ITranslator } from 'src/Infrastructure/Translations/ITranslator'; |
||
7 | |||
8 | @Injectable() |
||
9 | export class FairCalendarOverviewTableFactory { |
||
10 | constructor( |
||
11 | private readonly rowFactory: RowFactory, |
||
12 | @Inject('ITranslator') |
||
13 | private readonly translator: ITranslator |
||
14 | ) {} |
||
15 | |||
16 | public create(overview: ICalendarOverview): Table { |
||
17 | const columns = []; |
||
18 | const rowBuilder = this.rowFactory.createBuilder(); |
||
19 | |||
20 | const eventTypes: string[] = Object.values(EventType); |
||
21 | eventTypes.splice(-1, 0, 'leave'); |
||
22 | |||
23 | for (const type of eventTypes) { |
||
24 | columns.push( |
||
25 | this.translator.translate('faircalendar-type-option', { type }) |
||
26 | ); |
||
27 | rowBuilder.template('pages/faircalendar/_overview_badge.njk', { |
||
28 | type, |
||
29 | days: overview[type] |
||
30 | }); |
||
31 | } |
||
32 | |||
33 | const row = rowBuilder.build(); |
||
34 | |||
35 | return new Table(columns, [row]); |
||
36 | } |
||
37 | } |
||
38 |