Passed
Pull Request — master (#165)
by Mathieu
01:45
created

server/src/Domain/Accounting/Generators/AbstractGenerator.ts   A

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 20
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A AbstractGenerator.getCurrentYear 0 3 1
A AbstractGenerator.format 0 5 1
1
import { ConfigService } from '@nestjs/config';
2
import { IDateUtils } from 'src/Application/IDateUtils';
3
4
export abstract class AbstractGenerator {
5
  constructor(
6
    protected readonly dateUtils: IDateUtils,
7
    protected readonly configService: ConfigService
8
  ) {}
9
10
  protected async format(prefix: string, nbItem: number): Promise<string> {
11
    const pad = await this.configService.get<number>('ACCOUNTING_PAD');
12
13
    return `${prefix}-${this.getCurrentYear()}-${String(nbItem + 1).padStart(pad, '0')}`;
14
  }
15
16
  protected getCurrentYear(): number {
17
    return this.dateUtils.getCurrentDate().getFullYear();
18
  }
19
}
20