| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 39 |
| 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].days, |
||
| 30 | details: overview[type].details |
||
| 31 | }); |
||
| 32 | } |
||
| 33 | |||
| 34 | const row = rowBuilder.build(); |
||
| 35 | |||
| 36 | return new Table(columns, [row]); |
||
| 37 | } |
||
| 38 | } |
||
| 39 |