Total Complexity | 2 |
Total Lines | 21 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { Inject } from '@nestjs/common'; |
||
8 | |||
9 | @CommandHandler(CreateShippingCostCommand) |
||
10 | export class CreateShippingCostCommandHandler { |
||
11 | constructor( |
||
12 | @Inject('IShippingCostRepository') |
||
13 | private readonly shippingcostRepository: IShippingCostRepository, |
||
14 | private readonly isShippingCostAlreadyExist: IsShippingCostAlreadyExist |
||
15 | ) {} |
||
16 | |||
17 | public async execute(command: CreateShippingCostCommand): Promise<string> { |
||
18 | const { grams, price } = command; |
||
19 | |||
20 | if (true === (await this.isShippingCostAlreadyExist.isSatisfiedBy(grams))) { |
||
21 | throw new ShippingCostAlreadyExistException(); |
||
22 | } |
||
23 | |||
24 | const shippingCost = await this.shippingcostRepository.save( |
||
25 | new ShippingCost(grams, Math.round(price * 100)) |
||
26 | ); |
||
27 | |||
28 | return shippingCost.getId(); |
||
29 | } |
||
31 |