Total Complexity | 2 |
Total Lines | 25 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { |
||
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 | } |
||
39 |