Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 21 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {Injectable, Inject} from '@nestjs/common'; |
||
2 | import {IQuoteRepository} from './Repository/IQuoteRepository'; |
||
3 | import {IDateUtils} from 'src/Application/IDateUtils'; |
||
4 | |||
5 | @Injectable() |
||
6 | export class QuoteIdGenerator { |
||
7 | constructor( |
||
8 | @Inject('IQuoteRepository') |
||
9 | private readonly quoteRepository: IQuoteRepository, |
||
10 | @Inject('IDateUtils') |
||
11 | private readonly dateUtils: IDateUtils |
||
12 | ) {} |
||
13 | |||
14 | public async generate(): Promise<string> { |
||
15 | const year = this.dateUtils.getCurrentDate().getFullYear(); |
||
16 | const nbItem = await this.quoteRepository.countByYear(year); |
||
17 | |||
18 | return `FS-DEVIS-${year}-${String(nbItem + 1).padStart(4, '0')}`; |
||
19 | } |
||
20 | } |
||
21 |