Passed
Pull Request — master (#406)
by
unknown
01:44
created

server/src/Infrastructure/FairCalendar/Table/FairCalendarOverviewTableFactory.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 38
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 2
mnd 1
bc 1
fnc 1
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A FairCalendarOverviewTableFactory.create 0 21 2
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