|
1
|
|
|
import {Controller, Inject, Param, UseGuards, NotFoundException, Body, Put} from '@nestjs/common'; |
|
2
|
|
|
import {AuthGuard} from '@nestjs/passport'; |
|
3
|
|
|
import {ApiBearerAuth, ApiOperation, ApiTags} from '@nestjs/swagger'; |
|
4
|
|
|
import {UserAdministrativeView} from 'src/Application/HumanResource/User/View/UserAdministrativeView'; |
|
5
|
|
|
import {UserRole} from 'src/Domain/HumanResource/User/User.entity'; |
|
6
|
|
|
import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO'; |
|
7
|
|
|
import {Roles} from '../Decorator/Roles'; |
|
8
|
|
|
import {ICommandBus} from '@nestjs/cqrs'; |
|
9
|
|
|
import {UpdateUserCommand} from 'src/Application/HumanResource/User/Command/UpdateUserCommand'; |
|
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
|
|
|
try { |
|
27
|
|
|
return await this.commandBus.execute(new UpdateUserCommand( |
|
28
|
|
|
dto.id, |
|
29
|
|
|
userAdministrativeDto.role, |
|
30
|
|
|
userAdministrativeDto.annualEarnings, |
|
31
|
|
|
userAdministrativeDto.contract, |
|
32
|
|
|
userAdministrativeDto.executivePosition, |
|
33
|
|
|
userAdministrativeDto.healthInsurance, |
|
34
|
|
|
userAdministrativeDto.joiningDate, |
|
35
|
|
|
userAdministrativeDto.leavingDate, |
|
36
|
|
|
userAdministrativeDto.transportFee, |
|
37
|
|
|
)); |
|
38
|
|
|
} catch (e) { |
|
39
|
|
|
throw new NotFoundException(e.message); |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|