Passed
Pull Request — master (#152)
by Mathieu
01:58
created

server/src/Application/HumanResource/User/Query/GetUsersPresenceQueryHandler.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 36
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 30
mnd 1
bc 1
fnc 1
dl 0
loc 36
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetUsersPresenceQueryHandler.execute 0 17 2
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
import { UserPresenceView } from '../View/UserPresenceView';
8
9
@QueryHandler(GetUsersPresenceQuery)
10
export class GetUsersPresenceQueryHandler {
11
  constructor(
12
    @Inject('IUserRepository')
13
    private readonly userRepository: IUserRepository,
14
    @Inject('IDateUtils')
15
    private readonly dateUtils: IDateUtils
16
  ) {}
17
18
  public async execute(query: GetUsersPresenceQuery): Promise<UserPresenceView[]> {
19
    const currentDate = this.dateUtils.getCurrentDate();
20
    const workedDays = this.dateUtils.getWorkedDaysDuringAPeriod(currentDate, currentDate);
21
    const usersPresenceView: UserPresenceView[] = [];
22
23
    if (0 === workedDays.length) {
24
      return usersPresenceView;
25
    }
26
27
    const tst = await this.userRepository.findUsersPresences(currentDate);
28
    
29
    console.log(tst);
30
31
    
32
33
    return usersPresenceView;
34
  }
35
}
36