File size: 2,182 Bytes
f3abb0d
 
 
 
 
 
 
 
d201b18
f3abb0d
 
 
 
 
 
d201b18
f3abb0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 };
  }
}