Passed
Pull Request — master (#148)
by Mathieu
03:17
created

server/src/Infrastructure/HumanResource/Leave/Action/RefuseLeaveRequestAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 50
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A RefuseLeaveAction.index 0 17 2
1
import {
2
  Controller,
3
  Inject,
4
  BadRequestException,
5
  UseGuards,
6
  Param,
7
  Put,
8
  Body
9
} from '@nestjs/common';
10
import {AuthGuard} from '@nestjs/passport';
11
import {ApiTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
12
import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO';
13
import {Roles} from 'src/Infrastructure/HumanResource/User/Decorator/Roles';
14
import {UserRole, User} from 'src/Domain/HumanResource/User/User.entity';
15
import {RolesGuard} from 'src/Infrastructure/HumanResource/User/Security/RolesGuard';
16
import {RefuseLeaveCommand} from 'src/Application/HumanResource/Leave/Command/RefuseLeaveRequestCommand';
17
import {LoggedUser} from '../../User/Decorator/LoggedUser';
18
import {ICommandBus} from 'src/Application/ICommandBus';
19
import {ModerationDTO} from '../DTO/ModerationDTO';
20
21
@Controller('leaves')
22
@ApiTags('Human Resource')
23
@ApiBearerAuth()
24
@UseGuards(AuthGuard('bearer'), RolesGuard)
25
export class RefuseLeaveAction {
26
  constructor(
27
    @Inject('ICommandBus')
28
    private readonly commandBus: ICommandBus
29
  ) {}
30
31
  @Put(':id/refuse')
32
  @Roles(UserRole.COOPERATOR)
33
  @ApiOperation({summary: 'Refuse leave'})
34
  public async index(
35
    @Param() dto: IdDTO,
36
    @Body() moderation: ModerationDTO,
37
    @LoggedUser() user: User
38
  ) {
39
    try {
40
      const id = await this.commandBus.execute(
41
        new RefuseLeaveCommand(user, dto.id, moderation.comment)
42
      );
43
44
      return {id};
45
    } catch (e) {
46
      throw new BadRequestException(e.message);
47
    }
48
  }
49
}
50