Files
schedule-parser-next/src/users/users.controller.ts
2024-09-12 00:39:01 +04:00

31 lines
887 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}