Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 42 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
2 | import {Inject} from '@nestjs/common'; |
||
3 | import {GetDailyRateByIdQuery} from './GetDailyRateByIdQuery'; |
||
4 | import {TaskView} from 'src/Application/Task/View/TaskView'; |
||
5 | import {IDailyRateRepository} from 'src/Domain/Billing/Repository/IDailyRateRepository'; |
||
6 | import {DailyRateView} from '../../View/DailyRate/DailyRateView'; |
||
7 | import {DailyRateNotFoundException} from 'src/Domain/Billing/Exception/DailyRateNotFoundException'; |
||
8 | import {CustomerView} from 'src/Application/Customer/View/CustomerView'; |
||
9 | import {UserView} from 'src/Application/User/View/UserView'; |
||
10 | |||
11 | @QueryHandler(GetDailyRateByIdQuery) |
||
12 | export class GetDailyRateByIdQueryHandler { |
||
13 | constructor( |
||
14 | @Inject('IDailyRateRepository') |
||
15 | private readonly dailyRateRepository: IDailyRateRepository |
||
16 | ) {} |
||
17 | |||
18 | public async execute(query: GetDailyRateByIdQuery): Promise<DailyRateView> { |
||
19 | const dailyRate = await this.dailyRateRepository.findOneById(query.id); |
||
20 | if (!dailyRate) { |
||
21 | throw new DailyRateNotFoundException(); |
||
22 | } |
||
23 | |||
24 | const user = dailyRate.getUser(); |
||
25 | const customer = dailyRate.getCustomer(); |
||
26 | const task = dailyRate.getTask(); |
||
27 | |||
28 | return new DailyRateView( |
||
29 | dailyRate.getId(), |
||
30 | dailyRate.getAmount() / 100, |
||
31 | new UserView( |
||
32 | user.getId(), |
||
33 | user.getFirstName(), |
||
34 | user.getLastName(), |
||
35 | user.getEmail() |
||
36 | ), |
||
37 | new TaskView(task.getId(), task.getName()), |
||
38 | new CustomerView(customer.getId(), customer.getName()) |
||
39 | ); |
||
40 | } |
||
41 | } |
||
42 |