Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 45 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { |
||
2 | Body, |
||
3 | Post, |
||
4 | Controller, |
||
5 | Inject, |
||
6 | BadRequestException, |
||
7 | UseGuards |
||
8 | } from '@nestjs/common'; |
||
9 | import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger'; |
||
10 | import { AuthGuard } from '@nestjs/passport'; |
||
11 | import { ICommandBus } from 'src/Application/ICommandBus'; |
||
12 | import { UserRole } from 'src/Domain/HumanResource/User/User.entity'; |
||
13 | import { RolesGuard } from 'src/Infrastructure/HumanResource/User/Security/RolesGuard'; |
||
14 | import { Roles } from 'src/Infrastructure/HumanResource/User/Decorator/Roles'; |
||
15 | import { IncreaseUserSavingsRecordCommand } from 'src/Application/HumanResource/Savings/Command/IncreaseUserSavingsRecordCommand'; |
||
16 | import { UserSavingsRecordDTO } from '../DTO/UserSavingsRecordDTO'; |
||
17 | |||
18 | @Controller('users/savings-records') |
||
19 | @ApiTags('Human Resource') |
||
20 | @ApiBearerAuth() |
||
21 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
22 | export class IncreaseUserSavingsRecordAction { |
||
23 | constructor( |
||
24 | @Inject('ICommandBus') |
||
25 | private readonly commandBus: ICommandBus |
||
26 | ) {} |
||
27 | |||
28 | @Post('increase') |
||
29 | @Roles(UserRole.COOPERATOR, UserRole.EMPLOYEE) |
||
30 | @ApiOperation({ summary: 'Increase user savings record' }) |
||
31 | public async index( |
||
32 | @Body() { userId, amount }: UserSavingsRecordDTO, |
||
33 | ) { |
||
34 | try { |
||
35 | const id = await this.commandBus.execute( |
||
36 | new IncreaseUserSavingsRecordCommand(amount, userId) |
||
37 | ); |
||
38 | |||
39 | return { id }; |
||
40 | } catch (e) { |
||
41 | throw new BadRequestException(e.message); |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 |