| Total Complexity | 2 |
| Complexity/F | 2 |
| Lines of Code | 32 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import {Controller, Get, Inject, Param, UseGuards, NotFoundException} from '@nestjs/common'; |
||
| 2 | import {AuthGuard} from '@nestjs/passport'; |
||
| 3 | import {ApiBearerAuth, ApiOperation, ApiTags} from '@nestjs/swagger'; |
||
| 4 | import {Roles} from '../Decorator/Roles'; |
||
| 5 | import {IQueryBus} from '@nestjs/cqrs'; |
||
| 6 | import {UserAdministrativeView} from 'src/Application/HumanResource/User/View/UserAdministrativeView'; |
||
| 7 | import {GetUserAdministrativeByIdQuery} from 'src/Application/HumanResource/User/Query/GetUserAdministrativeByIdQuery'; |
||
| 8 | import {UserRole} from 'src/Domain/HumanResource/User/User.entity'; |
||
| 9 | import {IdDTO} from 'src/Infrastructure/Common/DTO/IdDTO'; |
||
| 10 | |||
| 11 | @Controller('users') |
||
| 12 | @ApiTags('Human Resource') |
||
| 13 | @ApiBearerAuth() |
||
| 14 | @UseGuards(AuthGuard('bearer')) |
||
| 15 | export class GetUserAdministrativeAction { |
||
| 16 | constructor( |
||
| 17 | @Inject('IQueryBus') |
||
| 18 | private readonly queryBus: IQueryBus |
||
| 19 | ) {} |
||
| 20 | |||
| 21 | @Get(':id') |
||
| 22 | @Roles(UserRole.COOPERATOR) |
||
| 23 | @ApiOperation({summary: 'Get user'}) |
||
| 24 | public async index(@Param() dto: IdDTO): Promise<UserAdministrativeView> { |
||
| 25 | try { |
||
| 26 | return await this.queryBus.execute(new GetUserAdministrativeByIdQuery(dto.id)); |
||
| 27 | } catch (e) { |
||
| 28 | throw new NotFoundException(e.message); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | } |
||
| 32 |