Total Complexity | 3 |
Total Lines | 26 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import { |
||
19 | |||
20 | @Controller('pay_slips') |
||
21 | @ApiUseTags('Human Resource') |
||
22 | @ApiBearerAuth() |
||
23 | @UseGuards(AuthGuard('bearer')) |
||
24 | export class DownloadPaySlipAction { |
||
25 | constructor( |
||
26 | @Inject('IQueryBus') |
||
27 | private readonly queryBus: IQueryBus |
||
28 | ) {} |
||
29 | |||
30 | @Get(':id/download') |
||
31 | @ApiOperation({title: 'Download payslip'}) |
||
32 | public async index(@Param() dto: IdDTO, @LoggedUser() loggedUser: User) { |
||
33 | try { |
||
34 | const {user, file}: PaySlipView = await this.queryBus.execute( |
||
35 | new GetPaySlipByIdQuery(dto.id) |
||
36 | ); |
||
37 | |||
38 | if (user.id !== loggedUser.getId()) { |
||
39 | throw new ForbiddenException(); |
||
40 | } |
||
41 | |||
42 | await this.queryBus.execute(new DownloadFileQuery(file.id)); |
||
43 | } catch (e) { |
||
44 | throw new BadRequestException(e.message); |
||
45 | } |
||
48 |