Passed
Pull Request — master (#287)
by
unknown
02:06
created

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

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 39
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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

1 Function

Rating   Name   Duplication   Size   Complexity  
A GetLeavesCalendarAction.index 0 17 2
1
import {
2
  Controller,
3
  Inject,
4
  BadRequestException,
5
  Get,
6
  Res
7
} from '@nestjs/common';
8
import { Response } from 'express';
9
import { ApiTags, ApiOperation } from '@nestjs/swagger';
10
import { GetLeavesCalendarQuery } from 'src/Application/HumanResource/Leave/Query/GetLeavesCalendarQuery';
11
import { IQueryBus } from 'src/Application/IQueryBus';
12
13
@Controller('leaves')
14
@ApiTags('Human Resource')
15
export class GetLeavesCalendarAction {
16
  constructor(
17
    @Inject('IQueryBus')
18
    private readonly queryBus: IQueryBus
19
  ) {}
20
21
  @Get('calendar.ics')
22
  @ApiOperation({ summary: 'Export leaves to iCalendar format' })
23
  public async index(@Res() res: Response): Promise<Response> {
24
    res.header('Content-Type', 'text/calendar;charset=UTF-8');
25
    res.header('Cache-Control', 'no-store, no-cache, must-revalidate');
26
    res.attachment('leaves.ics');
27
28
    let ics: string;
29
30
    try {
31
      ics = await this.queryBus.execute(new GetLeavesCalendarQuery());
32
    } catch (e) {
33
      throw new BadRequestException(e.message);
34
    }
35
36
    return res.send(ics);
37
  }
38
}
39