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

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

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 28
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 28
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 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
import { AbstractGenerator } from './AbstractGenerator';
6
7
@Injectable()
8
export class QuoteIdGenerator extends AbstractGenerator {
9
  constructor(
10
    @Inject('IQuoteRepository')
11
    private readonly quoteRepository: IQuoteRepository,
12
    @Inject('IDateUtils')
13
    protected readonly dateUtils: IDateUtils,
14
    protected readonly configService: ConfigService
15
  ) {
16
    super(dateUtils, configService);
17
  }
18
19
  public async generate(): Promise<string> {
20
    const [ prefix, nbItem ] = await Promise.all([
21
      this.configService.get<string>('ACCOUNTING_QUOTE_PREFIX'),
22
      this.quoteRepository.countByYear(this.getCurrentYear())
23
    ]);
24
25
    return this.format(prefix, nbItem);
26
  }
27
}
28