Passed
Pull Request — master (#406)
by
unknown
01:44
created

server/src/Infrastructure/FairCalendar/Controller/DeleteEventController.ts   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 42
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A DeleteEventController.post 0 13 2
1
import {
2
  BadRequestException,
3
  Controller,
4
  Inject,
5
  Param,
6
  Post,
7
  Res,
8
  UseGuards
9
} from '@nestjs/common';
10
import { Response } from 'express';
11
import { ICommandBus } from 'src/Application/ICommandBus';
12
import { IsAuthenticatedGuard } from 'src/Infrastructure/HumanResource/User/Security/IsAuthenticatedGuard';
13
import { LoggedUser } from 'src/Infrastructure/HumanResource/User/Decorator/LoggedUser';
14
import { User } from 'src/Domain/HumanResource/User/User.entity';
15
import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO';
16
import { WithName } from 'src/Infrastructure/Common/ExtendedRouting/WithName';
17
import { DeleteEventCommand } from 'src/Application/FairCalendar/Command/DeleteEventCommand';
18
19
@Controller('app/faircalendar/events/delete')
20
@UseGuards(IsAuthenticatedGuard)
21
export class DeleteEventController {
22
  constructor(
23
    @Inject('ICommandBus')
24
    private readonly commandBus: ICommandBus
25
  ) {}
26
27
  @Post(':id')
28
  @WithName('faircalendar_event_delete')
29
  public async post(
30
    @Param() dto: IdDTO,
31
    @LoggedUser() user: User,
32
    @Res() res: Response
33
  ) {
34
    try {
35
      await this.commandBus.execute(new DeleteEventCommand(dto.id, user));
36
      res.redirect(303, '/app/faircalendar');
37
    } catch (e) {
38
      throw new BadRequestException(e.message);
39
    }
40
  }
41
}
42