Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 34 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { GetDiscountsBySchoolQuery } from './GetDiscountsBySchoolQuery'; |
||
4 | import { IDiscountRepository } from 'src/Domain/School/Repository/IDiscountRepository'; |
||
5 | import { DiscountView } from '../../View/DiscountView'; |
||
6 | |||
7 | @QueryHandler(GetDiscountsBySchoolQuery) |
||
8 | export class GetDiscountsBySchoolQueryHandler { |
||
9 | constructor( |
||
10 | @Inject('IDiscountRepository') |
||
11 | private readonly discountRepository: IDiscountRepository |
||
12 | ) {} |
||
13 | |||
14 | public async execute({ schoolId }: GetDiscountsBySchoolQuery): Promise<DiscountView[]> { |
||
15 | const discountViews: DiscountView[] = []; |
||
16 | const discounts = await this.discountRepository.findBySchool( |
||
17 | schoolId |
||
18 | ); |
||
19 | |||
20 | for (const discount of discounts) { |
||
21 | discountViews.push( |
||
22 | new DiscountView( |
||
23 | discount.getId(), |
||
24 | discount.getType(), |
||
25 | discount.getAmount() / 100, |
||
26 | discount.getValue() / 100 |
||
27 | ) |
||
28 | ); |
||
29 | } |
||
30 | |||
31 | return discountViews; |
||
32 | } |
||
33 | } |
||
34 |