Passed
Push — master ( dd307e...6183fb )
by
unknown
04:54 queued 03:23
created

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

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 57
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A UpdateLeaveRequestAction.index 0 26 2
1
import {
2
  Body,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Put,
8
  Param,
9
} from '@nestjs/common';
10
import { AuthGuard } from '@nestjs/passport';
11
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
12
import { ICommandBus } from 'src/Application/ICommandBus';
13
import { LeaveRequestDTO } from '../DTO/LeaveRequestDTO';
14
import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard';
15
import { UserRole, } from 'src/Domain/HumanResource/User/User.entity';
16
import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles';
17
import { UpdateLeaveRequestCommand } from 'src/Application/HumanResource/Leave/Command/UpdateLeaveRequestCommand';
18
19
@Controller('leave-requests')
20
@ApiTags('Human Resource')
21
@ApiBearerAuth()
22
@UseGuards(AuthGuard('bearer'), RolesGuard)
23
export class UpdateLeaveRequestAction {
24
  constructor(
25
    @Inject('ICommandBus')
26
    private readonly commandBus: ICommandBus
27
  ) { }
28
29
  @Put(':id')
30
  @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE)
31
  @ApiOperation({ summary: 'Update existing leave request' })
32
  public async index(
33
    @Param() { id },
34
    @Body() dto: LeaveRequestDTO,
35
  ) {
36
    const { type, startDate, startsAllDay, endDate, endsAllDay, comment } = dto;
37
38
    try {
39
      await this.commandBus.execute(
40
        new UpdateLeaveRequestCommand(
41
          id,
42
          type,
43
          startDate,
44
          startsAllDay,
45
          endDate,
46
          endsAllDay,
47
          comment
48
        )
49
      );
50
51
      return { id };
52
    } catch (e) {
53
      throw new BadRequestException(e.message);
54
    }
55
  }
56
}
57