Passed
Pull Request — master (#70)
by Mathieu
01:36
created

server/src/Infrastructure/Billing/Action/CreateQuoteAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 47
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 42
mnd 1
bc 1
fnc 1
dl 0
loc 47
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A CreateQuoteAction.index 0 13 2
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 {projectId, customerId} = quoteDto;
37
      const id = await this.commandBus.execute(
38
        new CreateQuoteCommand(user, customerId, projectId)
39
      );
40
41
      return id;
42
    } catch (e) {
43
      throw new BadRequestException(e.message);
44
    }
45
  }
46
}
47