Passed
Pull Request — master (#406)
by
unknown
06:20
created

server/src/Infrastructure/Customer/Table/CustomerTableFactory.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 39
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A CustomerTableFactory.create 0 24 1
1
import { Injectable } from '@nestjs/common';
2
import { CustomerView } from 'src/Application/Customer/View/CustomerView';
3
import { RouteNameResolver } from 'src/Infrastructure/Common/ExtendedRouting/RouteNameResolver';
4
import { RowFactory } from 'src/Infrastructure/Tables/RowFactory';
5
import { Row, Table } from 'src/Infrastructure/Tables';
6
7
@Injectable()
8
export class CustomerTableFactory {
9
  constructor(
10
    private readonly resolver: RouteNameResolver,
11
    private readonly rowFactory: RowFactory
12
  ) {}
13
14
  public create(customers: CustomerView[]): Table {
15
    const columns = [
16
      'crm-customers-name',
17
      'crm-customers-street',
18
      'common-actions'
19
    ];
20
21
    const rows = customers.map(customer =>
22
      this.rowFactory
23
        .createBuilder()
24
        .value(customer.name)
25
        .template('pages/customers/_address.njk', { address: customer.address })
26
        .actions({
27
          edit: {
28
            url: this.resolver.resolve('crm_customers_edit', {
29
              id: customer.id
30
            })
31
          }
32
        })
33
        .build()
34
    );
35
36
    return new Table(columns, rows);
37
  }
38
}
39