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

server/src/Infrastructure/Activity/Action/DeleteActivityAction.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 45
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 40
mnd 1
bc 1
fnc 1
dl 0
loc 45
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 16 2
1
import {
2
  Delete,
3
  Controller,
4
  Inject,
5
  BadRequestException,
6
  UseGuards,
7
  Param
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 {DeleteActivityCommand} from 'src/Application/Activity/Command/DeleteActivityCommand';
15
import {DeleteActivityDTO} from './DTO/DeleteActivityDTO';
16
17
@Controller('activities')
18
@ApiUseTags('Activity')
19
@ApiBearerAuth()
20
@UseGuards(AuthGuard('bearer'))
21
export class DeleteActivityAction {
22
  constructor(
23
    @Inject('ICommandBus')
24
    private readonly commandBus: ICommandBus,
25
  ) {}
26
27
  @Delete(':id')
28
  @ApiOperation({title: 'Delete activity'})
29
  public async index(
30
    @Param() deleteActivityDto: DeleteActivityDTO,
31
    @LoggedUser() user: User
32
  ): Promise<any> {
33
    try {
34
      const {id: activityId} = deleteActivityDto;
35
      const id = await this.commandBus.execute(
36
        new DeleteActivityCommand(user, activityId)
37
      );
38
39
      return true;
40
    } catch (e) {
41
      throw new BadRequestException(e.message);
42
    }
43
  }
44
}
45