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

QuoteIdGenerator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1

1 Function

Rating   Name   Duplication   Size   Complexity  
A 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