Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 53 |
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 {ActivityView} from 'src/Application/Activity/View/ActivityView'; |
||
15 | import {IQueryBus} from 'src/Application/IQueryBus'; |
||
16 | import {GetActivityByIdQuery} from 'src/Application/Activity/Query/GetActivityByIdQuery'; |
||
17 | import {CreateQuoteCommand} from 'src/Application/Billing/Command/CreateQuoteCommand'; |
||
18 | import {QuoteDTO} from './DTO/QuoteDTO'; |
||
19 | |||
20 | @Controller('quotes') |
||
21 | @ApiUseTags('Billing') |
||
22 | @ApiBearerAuth() |
||
23 | @UseGuards(AuthGuard('bearer')) |
||
24 | export class CreateQuoteAction { |
||
25 | constructor( |
||
26 | @Inject('ICommandBus') |
||
27 | private readonly commandBus: ICommandBus, |
||
28 | @Inject('IQueryBus') |
||
29 | private readonly queryBus: IQueryBus |
||
30 | ) {} |
||
31 | |||
32 | @Post() |
||
33 | @ApiOperation({title: 'Create new quote'}) |
||
34 | public async index(@Body() quoteDto: QuoteDTO, @LoggedUser() user: User) { |
||
35 | try { |
||
36 | const {date, projectId, customerId, expiryDate} = quoteDto; |
||
37 | const id = await this.commandBus.execute( |
||
38 | new CreateQuoteCommand( |
||
39 | user, |
||
40 | new Date(date), |
||
41 | new Date(expiryDate), |
||
42 | customerId, |
||
43 | projectId |
||
44 | ) |
||
45 | ); |
||
46 | |||
47 | return id; |
||
48 | } catch (e) { |
||
49 | throw new BadRequestException(e.message); |
||
50 | } |
||
51 | } |
||
52 | } |
||
53 |