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

DeleteActivityAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 25
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A 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