Passed
Pull Request — master (#78)
by Mathieu
01:33
created

server/src/Domain/Billing/Quote/QuoteIdGenerator.ts   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 25
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A QuoteIdGenerator.generate 0 8 1
1
import {Injectable, Inject} from '@nestjs/common';
2
import {ConfigService} from '@nestjs/config';
3
import {IQuoteRepository} from '../Repository/IQuoteRepository';
4
import {IDateUtils} from 'src/Application/IDateUtils';
5
6
@Injectable()
7
export class QuoteIdGenerator {
8
  constructor(
9
    @Inject('IQuoteRepository')
10
    private readonly quoteRepository: IQuoteRepository,
11
    @Inject('IDateUtils')
12
    private readonly dateUtils: IDateUtils,
13
    private readonly configService: ConfigService
14
  ) {}
15
16
  public async generate(): Promise<string> {
17
    const year = this.dateUtils.getCurrentDate().getFullYear();
18
    const prefix = await this.configService.get<string>('BILLING_QUOTE_PREFIX');
19
    const pad = await this.configService.get<number>('BILLING_QUOTE_PAD');
20
    const nbItem = await this.quoteRepository.countByYear(year);
21
22
    return `${prefix}-${year}-${String(nbItem + 1).padStart(pad, '0')}`;
23
  }
24
}
25