| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 32 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
| 2 | import { Inject } from '@nestjs/common'; |
||
| 3 | import { GetUsersByRoleQuery } from './GetUsersByRoleQuery'; |
||
| 4 | import { IUserRepository } from 'src/Domain/User/Repository/IUserRepository'; |
||
| 5 | import { UserSummaryView } from '../View/UserSummaryView'; |
||
| 6 | |||
| 7 | @QueryHandler(GetUsersByRoleQuery) |
||
| 8 | export class GetUsersByRoleQueryHandler { |
||
| 9 | constructor( |
||
| 10 | @Inject('IUserRepository') |
||
| 11 | private readonly userRepository: IUserRepository |
||
| 12 | ) {} |
||
| 13 | |||
| 14 | public async execute({ role }: GetUsersByRoleQuery): Promise<UserSummaryView[]> { |
||
| 15 | const users = await this.userRepository.findUsersByRole(role); |
||
| 16 | const userViews: UserSummaryView[] = []; |
||
| 17 | |||
| 18 | for (const user of users) { |
||
| 19 | userViews.push( |
||
| 20 | new UserSummaryView( |
||
| 21 | user.getId(), |
||
| 22 | user.getFirstName(), |
||
| 23 | user.getLastName(), |
||
| 24 | user.getEmail(), |
||
| 25 | ) |
||
| 26 | ); |
||
| 27 | } |
||
| 28 | |||
| 29 | return userViews; |
||
| 30 | } |
||
| 31 | } |
||
| 32 |