Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 25 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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 | |||
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 |