import { Controller, Get, Request, Post, UseGuards, Body, Param, BadRequestException } from '@nestjs/common'; import { User } from 'src/decorators/user.decorator'; import { JwtAuthGuard } from '../../src/modules/auth/jwt-auth.guard'; import { AppAuthenticationDto, AppForgotPasswordDto, AppPasswordResetDto } from '@dto/app-authentication.dto'; import { AuthService } from '../services/auth.service'; @Controller() export class AppController { constructor(private authService: AuthService) {} @Post(['authenticate', 'authenticate/:organizationId']) async login(@Body() appAuthDto: AppAuthenticationDto, @Param('organizationId') organizationId) { return this.authService.login(appAuthDto.email, appAuthDto.password, organizationId); } @UseGuards(JwtAuthGuard) @Get('switch/:organizationId') async switch(@Param('organizationId') organizationId, @User() user) { if (!organizationId) { throw new BadRequestException(); } return await this.authService.switchOrganization(organizationId, user); } @Post('signup') async signup(@Body() appAuthDto: AppAuthenticationDto) { return this.authService.signup(appAuthDto.email); } @Post('/forgot_password') async forgotPassword(@Body() appAuthDto: AppForgotPasswordDto) { await this.authService.forgotPassword(appAuthDto.email); return {}; } @Post('/reset_password') async resetPassword(@Body() appAuthDto: AppPasswordResetDto) { const { token, password } = appAuthDto; await this.authService.resetPassword(token, password); return {}; } @Get('/health') async healthCheck(@Request() req) { return { works: 'yeah' }; } }