streamflix-api / src /modules /super-admin /auth /auth.controller.ts
Akshar2325
feat(discord-logger): implement api request and response logging
d201b18
Raw
History Blame
2.18 kB
import { Controller, Post, Body, Req, UseGuards } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
import { SuperAdminAuthService } from './auth.service';
import { SuperAdminRegisterDto } from './dto/register.dto';
import { SuperAdminLoginDto } from './dto/login.dto';
import { SuperAdminRefreshTokenDto } from './dto/refresh-token.dto';
import { Public } from 'src/shared/decorators/public.decorator';
import { GetSuperAdmin } from 'src/shared/decorators/get-super-admin.decorator';
import { LogToDiscord } from 'src/shared/decorators/log-to-discord.decorator';
import type { SuperAdminSessionType } from 'src/shared/types/super-admin-session.type';
import { SuperAdminAuthGuard } from './guards/super-admin-auth.guard';
@ApiTags('Super Admin: Authentication')
@Controller('super-admin/auth')
@UseGuards(SuperAdminAuthGuard)
@LogToDiscord()
export class SuperAdminAuthController {
constructor(private readonly superAdminAuthService: SuperAdminAuthService) {}
@Public()
@Post('register')
@ApiOperation({ summary: 'Register a new super admin' })
async register(
@Body() registerDto: SuperAdminRegisterDto,
@Req() request: any,
) {
return this.superAdminAuthService.register(registerDto, request);
}
@Public()
@Post('login')
@ApiOperation({ summary: 'Login super admin' })
async login(@Body() loginDto: SuperAdminLoginDto, @Req() request: any) {
return this.superAdminAuthService.login(loginDto, request);
}
@ApiBearerAuth()
@Post('logout')
@ApiOperation({ summary: 'Logout super admin' })
async logout(@GetSuperAdmin() sessionData: SuperAdminSessionType) {
return this.superAdminAuthService.logout(sessionData);
}
@Public()
@Post('refresh-token')
@ApiOperation({ summary: 'Refresh access token' })
async refreshToken(@Body() refreshTokenDto: SuperAdminRefreshTokenDto) {
return this.superAdminAuthService.refreshToken(refreshTokenDto);
}
@ApiBearerAuth()
@Post('profile')
@ApiOperation({ summary: 'Get super admin profile' })
async getProfile(@GetSuperAdmin() sessionData: SuperAdminSessionType) {
return { superAdmin: sessionData.superAdmin };
}
}