Passed
Pull Request — master (#182)
by
unknown
02:05
created

server/src/Infrastructure/HumanResource/MealTicket/Action/CreateMealTicketRemovalAction.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
eloc 42
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 2
mnd 1
bc 1
fnc 1
bpm 1
cpm 2
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A CreateMealTicketRemovalAction.index 0 16 2
1
import {
2
  Body,
3
  Post,
4
  Controller,
5
  Inject,
6
  BadRequestException,
7
  UseGuards
8
} from '@nestjs/common';
9
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
10
import { AuthGuard } from '@nestjs/passport';
11
import { ICommandBus } from 'src/Application/ICommandBus';
12
import { MealTicketRemovalDTO } from '../DTO/MealTicketRemovalDTO';
13
import { User, UserRole } from 'src/Domain/HumanResource/User/User.entity';
14
import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard';
15
import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles';
16
import { LoggedUser } from '../../User/Decorator/LoggedUser';
17
import { CreateMealTicketRemovalCommand } from 'src/Application/HumanResource/MealTicket/Command/CreateMealTicketRemovalCommand';
18
19
@Controller('meal-tickets-removals')
20
@ApiTags('Human Resource')
21
@ApiBearerAuth()
22
@UseGuards(AuthGuard('bearer'), RolesGuard)
23
export class CreateMealTicketRemovalAction {
24
  constructor(
25
    @Inject('ICommandBus')
26
    private readonly commandBus: ICommandBus
27
  ) {}
28
29
  @Post()
30
  @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE)
31
  @ApiOperation({ summary: 'Create new meal ticket removal' })
32
  public async index(
33
    @Body() { date, comment }: MealTicketRemovalDTO,
34
    @LoggedUser() user: User
35
  ) {
36
    try {
37
      const id = await this.commandBus.execute(
38
        new CreateMealTicketRemovalCommand(date, comment, user)
39
      );
40
41
      return { id };
42
    } catch (e) {
43
      throw new BadRequestException(e.message);
44
    }
45
  }
46
}
47