Passed
Pull Request — master (#78)
by Mathieu
01:25
created

server/src/Application/Billing/Command/DailyRate/AbstractUserCustomerAndTaskGetter.ts   A

Complexity

Total Complexity 6
Complexity/F 2

Size

Lines of Code 45
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 37
mnd 3
bc 3
fnc 3
dl 0
loc 45
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A AbstractUserCustomerAndTaskGetter.getTask 0 8 2
A AbstractUserCustomerAndTaskGetter.getUser 0 8 2
A AbstractUserCustomerAndTaskGetter.getCustomer 0 8 2
1
import {Task} from 'src/Domain/Task/Task.entity';
2
import {User} from 'src/Domain/User/User.entity';
3
import {Customer} from 'src/Domain/Customer/Customer.entity';
4
import {CustomerNotFoundException} from 'src/Domain/Customer/Exception/CustomerNotFoundException';
5
import {UserNotFoundException} from 'src/Domain/User/Exception/UserNotFoundException';
6
import {ITaskRepository} from 'src/Domain/Task/Repository/ITaskRepository';
7
import {IUserRepository} from 'src/Domain/User/Repository/IUserRepository';
8
import {ICustomerRepository} from 'src/Domain/Customer/Repository/ICustomerRepository';
9
import {TaskNotFoundException} from 'src/Domain/Task/Exception/TaskNotFoundException';
10
11
export abstract class AbstractUserCustomerAndTaskGetter {
12
  constructor(
13
    private readonly taskRepository: ITaskRepository,
14
    private readonly userRepository: IUserRepository,
15
    private readonly customerRepository: ICustomerRepository
16
  ) {}
17
18
  protected async getTask(taskId: string): Promise<Task> {
19
    const task = await this.taskRepository.findOneById(taskId);
20
    if (!task) {
21
      throw new TaskNotFoundException();
22
    }
23
24
    return task;
25
  }
26
27
  protected async getCustomer(customerId: string): Promise<Customer> {
28
    const customer = await this.customerRepository.findOneById(customerId);
29
    if (!customer) {
30
      throw new CustomerNotFoundException();
31
    }
32
33
    return customer;
34
  }
35
36
  protected async getUser(userId: string): Promise<User> {
37
    const user = await this.userRepository.findOneById(userId);
38
    if (!user) {
39
      throw new UserNotFoundException();
40
    }
41
42
    return user;
43
  }
44
}
45