Passed
Pull Request — master (#63)
by Nicolas
01:22
created

server/src/Infrastructure/Activity/Action/DeleteActivityAction.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
rs 10
bpm 1
cpm 2
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A DeleteActivityAction.index 0 17 2
1
import {
2
  Delete,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Param,
8
  HttpCode
9
} from '@nestjs/common';
10
import {AuthGuard} from '@nestjs/passport';
11
import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
12
import {ICommandBus} from 'src/Application/ICommandBus';
13
import {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser';
14
import {User} from 'src/Domain/User/User.entity';
15
import {DeleteActivityCommand} from 'src/Application/Activity/Command/DeleteActivityCommand';
16
import {DeleteActivityDTO} from './DTO/DeleteActivityDTO';
17
18
@Controller('activities')
19
@ApiUseTags('Activity')
20
@ApiBearerAuth()
21
@UseGuards(AuthGuard('bearer'))
22
export class DeleteActivityAction {
23
  constructor(
24
    @Inject('ICommandBus')
25
    private readonly commandBus: ICommandBus
26
  ) {}
27
28
  @Delete(':id')
29
  @ApiOperation({title: 'Delete activity'})
30
  @HttpCode(204)
31
  public async index(
32
    @Param() deleteActivityDto: DeleteActivityDTO,
33
    @LoggedUser() user: User
34
  ): Promise<boolean> {
35
    try {
36
      const {id: activityId} = deleteActivityDto;
37
      await this.commandBus.execute(
38
        new DeleteActivityCommand(user, activityId)
39
      );
40
41
      return true;
42
    } catch (e) {
43
      throw new BadRequestException(e.message);
44
    }
45
  }
46
}
47