Total Complexity | 2 |
Complexity/F | 2 |
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 {GetDailyRatesQuery} from './GetDailyRatesQuery'; |
||
4 | import {IDailyRateRepository} from 'src/Domain/Billing/Repository/IDailyRateRepository'; |
||
5 | import {DailyRateView} from '../../View/DailyRate/DailyRateView'; |
||
6 | import {UserView} from 'src/Application/User/View/UserView'; |
||
7 | import {TaskView} from 'src/Application/Task/View/TaskView'; |
||
8 | import {CustomerView} from 'src/Application/Customer/View/CustomerView'; |
||
9 | |||
10 | @QueryHandler(GetDailyRatesQuery) |
||
11 | export class GetDailyRatesQueryHandler { |
||
12 | constructor( |
||
13 | @Inject('IDailyRateRepository') |
||
14 | private readonly dailyRateRepository: IDailyRateRepository |
||
15 | ) {} |
||
16 | |||
17 | public async execute(query: GetDailyRatesQuery): Promise<DailyRateView[]> { |
||
18 | const dailyRates = await this.dailyRateRepository.findAll(); |
||
19 | const results: DailyRateView[] = []; |
||
20 | |||
21 | for (const dailyRate of dailyRates) { |
||
22 | const user = dailyRate.getUser(); |
||
23 | const task = dailyRate.getTask(); |
||
24 | const customer = dailyRate.getCustomer(); |
||
25 | |||
26 | results.push( |
||
27 | new DailyRateView( |
||
28 | dailyRate.getId(), |
||
29 | dailyRate.getAmount() / 100, |
||
30 | new UserView( |
||
31 | user.getId(), |
||
32 | user.getFirstName(), |
||
33 | user.getLastName(), |
||
34 | user.getEmail() |
||
35 | ), |
||
36 | new TaskView(task.getId(), task.getName()), |
||
37 | new CustomerView(customer.getId(), customer.getName()) |
||
38 | ) |
||
39 | ); |
||
40 | } |
||
41 | |||
42 | return results; |
||
43 | } |
||
44 | } |
||
45 |