Passed
Pull Request — master (#165)
by Mathieu
03:20 queued 01:35
created

AbstractGenerator.format   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
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