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

QuoteIdGenerator.generate   A

Complexity

Conditions 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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