Total Complexity | 3 |
Complexity/F | 3 |
Lines of Code | 45 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { GetUsersPresenceQuery } from './GetUsersPresenceQuery'; |
||
4 | import { UserView } from '../View/UserView'; |
||
5 | import { IUserRepository } from 'src/Domain/HumanResource/User/Repository/IUserRepository'; |
||
6 | import { IDateUtils } from 'src/Application/IDateUtils'; |
||
7 | |||
8 | @QueryHandler(GetUsersPresenceQuery) |
||
9 | export class GetUsersPresenceQueryHandler { |
||
10 | constructor( |
||
11 | @Inject('IUserRepository') |
||
12 | private readonly userRepository: IUserRepository, |
||
13 | @Inject('IDateUtils') |
||
14 | private readonly dateUtils: IDateUtils |
||
15 | ) {} |
||
16 | |||
17 | public async execute(query: GetUsersPresenceQuery): Promise<UserView[]> { |
||
18 | const currentDate = this.dateUtils.getCurrentDate(); |
||
19 | const workedDays = this.dateUtils.getWorkedDaysDuringAPeriod(currentDate, currentDate); |
||
20 | |||
21 | if (0 === workedDays.length) { |
||
22 | console.log('innn'); |
||
23 | } |
||
24 | |||
25 | |||
26 | |||
27 | const users = await this.userRepository.findUsers(false); |
||
28 | const userViews: UserView[] = []; |
||
29 | |||
30 | for (const user of users) { |
||
31 | userViews.push( |
||
32 | new UserView( |
||
33 | user.getId(), |
||
34 | user.getFirstName(), |
||
35 | user.getLastName(), |
||
36 | user.getEmail(), |
||
37 | user.getRole() |
||
38 | ) |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | return userViews; |
||
43 | } |
||
44 | } |
||
45 |