import { Body, ClassSerializerInterceptor, Controller, Get, Inject, Post, UseGuards, UseInterceptors, } from '@nestjs/common'; import { ClientProxy } from '@nestjs/microservices'; import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger'; import { LoginDto } from './dtos/login.dto'; import { User } from '../../decorators/user.decorator'; import { UserInfo } from '@freeblox/shared'; import { lastValueFrom } from 'rxjs'; import { AuthGuard } from '../../guards/auth.guard'; import { UserDto } from './dtos/user.dto'; @Controller({ version: '1', path: 'auth', }) @ApiBearerAuth() @ApiTags('Auth') @UseInterceptors(ClassSerializerInterceptor) export class AuthController { constructor(@Inject('auth') private auth: ClientProxy) {} @Post('login') async login(@Body() body: LoginDto) { return this.auth.send('auth.login', { body }); } @Get('me') @ApiOkResponse({ type: UserDto }) @UseGuards(AuthGuard) async myInfo(@User() user: UserInfo): Promise { return lastValueFrom(this.auth.send('auth.getUserById', { id: user.sub })); } @Get('bans') @UseGuards(AuthGuard) async banInfo(@User() user: UserInfo) { return lastValueFrom(this.auth.send('auth.getUserBans', { user })); } }