| Total Complexity | 6 |
| Complexity/F | 2 |
| Lines of Code | 45 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 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 |