mirror of
https://github.com/n08i40k/schedule-parser-next.git
synced 2025-12-06 09:47:46 +03:00
31 lines
887 B
TypeScript
31 lines
887 B
TypeScript
import {
|
||
Controller,
|
||
Get,
|
||
HttpCode,
|
||
HttpStatus,
|
||
NotFoundException,
|
||
UseGuards,
|
||
} from "@nestjs/common";
|
||
import { AuthGuard } from "../auth/auth.guard";
|
||
import { ClientUserDto } from "../dto/user.dto";
|
||
import { ResultDto } from "../utility/validation/class-validator.interceptor";
|
||
import { UserToken } from "../auth/auth.decorator";
|
||
import { AuthService } from "../auth/auth.service";
|
||
|
||
@Controller("api/v1/users")
|
||
@UseGuards(AuthGuard)
|
||
export class UsersController {
|
||
constructor(private readonly authService: AuthService) {}
|
||
|
||
@ResultDto(ClientUserDto)
|
||
@HttpCode(HttpStatus.OK)
|
||
@Get("me")
|
||
async getMe(@UserToken() token: string): Promise<ClientUserDto> {
|
||
const userDto = await this.authService.decodeUserToken(token);
|
||
if (!userDto)
|
||
throw new NotFoundException("Не удалось найти пользователя!");
|
||
|
||
return ClientUserDto.fromUserDto(userDto);
|
||
}
|
||
}
|