2023-06-29 14:13:57 +00:00
|
|
|
import {
|
|
|
|
Body,
|
|
|
|
ClassSerializerInterceptor,
|
|
|
|
Controller,
|
2023-06-30 18:29:34 +00:00
|
|
|
Get,
|
2023-06-29 14:13:57 +00:00
|
|
|
Inject,
|
|
|
|
Post,
|
2023-06-30 18:29:34 +00:00
|
|
|
UseGuards,
|
2023-06-29 14:13:57 +00:00
|
|
|
UseInterceptors,
|
|
|
|
} from '@nestjs/common';
|
|
|
|
import { ClientProxy } from '@nestjs/microservices';
|
2023-06-30 18:29:34 +00:00
|
|
|
import { ApiBearerAuth, ApiOkResponse, ApiTags } from '@nestjs/swagger';
|
2023-06-29 14:13:57 +00:00
|
|
|
import { LoginDto } from './dtos/login.dto';
|
2023-06-30 18:29:34 +00:00
|
|
|
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';
|
2023-06-29 14:13:57 +00:00
|
|
|
|
|
|
|
@Controller({
|
|
|
|
version: '1',
|
|
|
|
path: 'auth',
|
|
|
|
})
|
2023-06-30 18:29:34 +00:00
|
|
|
@ApiBearerAuth()
|
2023-06-29 14:13:57 +00:00
|
|
|
@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 });
|
|
|
|
}
|
2023-06-30 18:29:34 +00:00
|
|
|
|
|
|
|
@Get('me')
|
|
|
|
@ApiOkResponse({ type: UserDto })
|
|
|
|
@UseGuards(AuthGuard)
|
|
|
|
async myInfo(@User() user: UserInfo): Promise<UserDto> {
|
|
|
|
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 }));
|
|
|
|
}
|
2023-06-29 14:13:57 +00:00
|
|
|
}
|