Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 51 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Body, |
||
3 | Post, |
||
4 | Controller, |
||
5 | Inject, |
||
6 | BadRequestException, |
||
7 | UseGuards |
||
8 | } from '@nestjs/common'; |
||
9 | import {AuthGuard} from '@nestjs/passport'; |
||
10 | import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger'; |
||
11 | import {ICommandBus} from 'src/Application/ICommandBus'; |
||
12 | import {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser'; |
||
13 | import {User} from 'src/Domain/User/User.entity'; |
||
14 | import {IQueryBus} from 'src/Application/IQueryBus'; |
||
15 | import {CreateQuoteCommand} from 'src/Application/Billing/Command/CreateQuoteCommand'; |
||
16 | import {CreateQuoteDTO} from './DTO/CreateQuoteDTO'; |
||
17 | import {CreateQuoteItemsCommand} from 'src/Application/Billing/Command/CreateQuoteItemsCommand'; |
||
18 | |||
19 | @Controller('quotes') |
||
20 | @ApiUseTags('Billing') |
||
21 | @ApiBearerAuth() |
||
22 | @UseGuards(AuthGuard('bearer')) |
||
23 | export class CreateQuoteAction { |
||
24 | constructor( |
||
25 | @Inject('ICommandBus') |
||
26 | private readonly commandBus: ICommandBus, |
||
27 | @Inject('IQueryBus') |
||
28 | private readonly queryBus: IQueryBus |
||
29 | ) {} |
||
30 | |||
31 | @Post() |
||
32 | @ApiOperation({title: 'Create new quote'}) |
||
33 | public async index( |
||
34 | @Body() quoteDTO: CreateQuoteDTO, |
||
35 | @LoggedUser() user: User |
||
36 | ) { |
||
37 | try { |
||
38 | const {projectId, customerId, status, items} = quoteDTO; |
||
39 | const id = await this.commandBus.execute( |
||
40 | new CreateQuoteCommand(user, status, customerId, projectId) |
||
41 | ); |
||
42 | |||
43 | await this.commandBus.execute(new CreateQuoteItemsCommand(id, items)); |
||
44 | |||
45 | return id; |
||
46 | } catch (e) { |
||
47 | throw new BadRequestException(e.message); |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 |