| Total Complexity | 1 |
| Complexity/F | 1 |
| Lines of Code | 30 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | import { Controller, Get, Inject, UseGuards } from '@nestjs/common'; |
||
| 2 | import { AuthGuard } from '@nestjs/passport'; |
||
| 3 | import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger'; |
||
| 4 | import { IQueryBus } from 'src/Application/IQueryBus'; |
||
| 5 | import { GetUserByIdQuery } from 'src/Application/User/Query/GetUserByIdQuery'; |
||
| 6 | import { UserView } from 'src/Application/User/View/UserView'; |
||
| 7 | import { UserRole } from 'src/Domain/User/User.entity'; |
||
| 8 | import { LoggedUser } from '../Decorator/LoggedUser'; |
||
| 9 | import { Roles } from '../Decorator/Roles'; |
||
| 10 | import { RolesGuard } from '../Security/RolesGuard'; |
||
| 11 | import { UserAuthView } from '../Security/UserAuthView'; |
||
| 12 | |||
| 13 | @Controller('users') |
||
| 14 | @ApiTags('User') |
||
| 15 | @ApiBearerAuth() |
||
| 16 | @UseGuards(AuthGuard('bearer'), RolesGuard) |
||
| 17 | export class GetMeAction { |
||
| 18 | constructor( |
||
| 19 | @Inject('IQueryBus') |
||
| 20 | private readonly queryBus: IQueryBus |
||
| 21 | ) {} |
||
| 22 | |||
| 23 | @Get('me') |
||
| 24 | @Roles(UserRole.PHOTOGRAPHER, UserRole.DIRECTOR) |
||
| 25 | @ApiOperation({ summary: 'Get current user' }) |
||
| 26 | public async index(@LoggedUser() { id }: UserAuthView): Promise<UserView> { |
||
| 27 | return await this.queryBus.execute(new GetUserByIdQuery(id)); |
||
| 28 | } |
||
| 29 | } |
||
| 30 |