Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 29 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { QueryHandler } from '@nestjs/cqrs'; |
||
2 | import { Inject } from '@nestjs/common'; |
||
3 | import { IShippingCostRepository } from 'src/Domain/Order/Repository/IShippingCostRepository'; |
||
4 | import { ShippingCostView } from '../../View/ShippingCostView'; |
||
5 | import { ShippingCostNotFoundException } from 'src/Domain/Order/Exception/ShippingCostNotFoundException'; |
||
6 | import { GetShippingCostByIdQuery } from './GetShippingCostByIdQuery'; |
||
7 | |||
8 | @QueryHandler(GetShippingCostByIdQuery) |
||
9 | export class GetShippingCostByIdQueryHandler { |
||
10 | constructor( |
||
11 | @Inject('IShippingCostRepository') |
||
12 | private readonly shippingcostRepository: IShippingCostRepository |
||
13 | ) {} |
||
14 | |||
15 | public async execute(query: GetShippingCostByIdQuery): Promise<ShippingCostView> { |
||
16 | const shippingCost = await this.shippingcostRepository.findOneById(query.id); |
||
17 | |||
18 | if (!shippingCost) { |
||
19 | throw new ShippingCostNotFoundException(); |
||
20 | } |
||
21 | |||
22 | return new ShippingCostView( |
||
23 | shippingCost.getId(), |
||
24 | shippingCost.getGrams(), |
||
25 | shippingCost.getPriceFromCents(), |
||
26 | ); |
||
27 | } |
||
28 | } |
||
29 |