| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 31 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 2 | import { Inject } from '@nestjs/common'; |
||
| 3 | import { GetSchoolVouchersQuery } from './GetSchoolVouchersQuery'; |
||
| 4 | import { IVoucherRepository } from 'src/Domain/School/Repository/IVoucherRepository'; |
||
| 5 | import { SchoolUserView } from '../../View/SchoolUserView'; |
||
| 6 | |||
| 7 | @QueryHandler(GetSchoolVouchersQuery) |
||
| 8 | export class GetSchoolVouchersQueryHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('IVoucherRepository') |
||
| 11 | private readonly voucherRepository: IVoucherRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute(query: GetSchoolVouchersQuery): Promise<SchoolUserView[]> { |
||
| 15 | const schoolUserViews: SchoolUserView[] = []; |
||
| 16 | const vouchers = await this.voucherRepository.findBySchool(query.schoolId); |
||
| 17 | |||
| 18 | for (const voucher of vouchers) { |
||
| 19 | schoolUserViews.push( |
||
| 20 | new SchoolUserView( |
||
| 21 | voucher.getId(), |
||
| 22 | voucher.getEmail(), |
||
| 23 | 'voucher' |
||
| 24 | ) |
||
| 25 | ); |
||
| 26 | } |
||
| 27 | |||
| 28 | return schoolUserViews; |
||
| 29 | } |
||
| 30 | } |
||
| 31 |