Total Complexity | 2 |
Complexity/F | 2 |
Lines of Code | 54 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Body, Controller, Inject, NotFoundException, Param, Put, UseGuards } from '@nestjs/common'; |
||
2 | import { ICommandBus } from '@nestjs/cqrs'; |
||
3 | import { AuthGuard } from '@nestjs/passport'; |
||
4 | import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; |
||
5 | import { UpdateUserCommand } from 'src/Application/HumanResource/User/Command/UpdateUserCommand'; |
||
6 | import { UserAdministrativeView } from 'src/Application/HumanResource/User/View/UserAdministrativeView'; |
||
7 | import { UserRole } from 'src/Domain/HumanResource/User/User.entity'; |
||
8 | import { IdDTO } from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
9 | import { Roles } from '../Decorator/Roles'; |
||
10 | import { UserAdministrativeDTO } from '../DTO/UserAdministrativeDTO'; |
||
11 | |||
12 | @Controller('users') |
||
13 | @ApiTags('Human Resource') |
||
14 | @ApiBearerAuth() |
||
15 | @UseGuards(AuthGuard('bearer')) |
||
16 | export class UpdateUserAction { |
||
17 | constructor( |
||
18 | @Inject('ICommandBus') |
||
19 | private readonly commandBus: ICommandBus |
||
20 | ) {} |
||
21 | |||
22 | @Put(':id/administrative') |
||
23 | @Roles(UserRole.COOPERATOR) |
||
24 | @ApiOperation({summary: 'Update user administrative info'}) |
||
25 | public async index(@Param() dto: IdDTO, @Body() userAdministrativeDto: UserAdministrativeDTO): Promise<UserAdministrativeView> { |
||
26 | const { |
||
27 | role, |
||
28 | annualEarnings, |
||
29 | contract, |
||
30 | executivePosition, |
||
31 | healthInsurance, |
||
32 | joiningDate, |
||
33 | leavingDate, |
||
34 | transportFee, |
||
35 | } = userAdministrativeDto; |
||
36 | |||
37 | try { |
||
38 | return await this.commandBus.execute(new UpdateUserCommand( |
||
39 | dto.id, |
||
40 | role, |
||
41 | annualEarnings, |
||
42 | contract, |
||
43 | executivePosition, |
||
44 | healthInsurance, |
||
45 | joiningDate, |
||
46 | leavingDate, |
||
47 | transportFee, |
||
48 | )); |
||
49 | } catch (e) { |
||
50 | throw new NotFoundException(e.message); |
||
51 | } |
||
52 | } |
||
53 | } |
||
54 |