2022-05-05 07:08:42 +00:00
|
|
|
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';
|
2022-04-20 09:16:57 +00:00
|
|
|
import { AppAuthenticationDto, AppForgotPasswordDto, AppPasswordResetDto } from '@dto/app-authentication.dto';
|
2021-07-11 05:39:55 +00:00
|
|
|
import { AuthService } from '../services/auth.service';
|
2021-07-08 05:40:27 +00:00
|
|
|
|
|
|
|
|
@Controller()
|
|
|
|
|
export class AppController {
|
2021-07-08 07:39:07 +00:00
|
|
|
constructor(private authService: AuthService) {}
|
2021-07-08 05:40:27 +00:00
|
|
|
|
2022-05-05 07:08:42 +00:00
|
|
|
@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);
|
2021-07-08 07:39:07 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-19 05:42:16 +00:00
|
|
|
@Post('signup')
|
2022-04-20 09:16:57 +00:00
|
|
|
async signup(@Body() appAuthDto: AppAuthenticationDto) {
|
2022-05-05 07:08:42 +00:00
|
|
|
return this.authService.signup(appAuthDto.email);
|
2021-07-19 05:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-26 16:02:47 +00:00
|
|
|
@Post('/forgot_password')
|
2022-04-20 09:16:57 +00:00
|
|
|
async forgotPassword(@Body() appAuthDto: AppForgotPasswordDto) {
|
|
|
|
|
await this.authService.forgotPassword(appAuthDto.email);
|
2021-09-21 13:48:28 +00:00
|
|
|
return {};
|
2021-07-26 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Post('/reset_password')
|
2022-04-20 09:16:57 +00:00
|
|
|
async resetPassword(@Body() appAuthDto: AppPasswordResetDto) {
|
|
|
|
|
const { token, password } = appAuthDto;
|
2021-07-26 16:02:47 +00:00
|
|
|
await this.authService.resetPassword(token, password);
|
2021-09-21 13:48:28 +00:00
|
|
|
return {};
|
2021-07-26 16:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
2021-07-31 08:45:03 +00:00
|
|
|
@Get('/health')
|
|
|
|
|
async healthCheck(@Request() req) {
|
|
|
|
|
return { works: 'yeah' };
|
|
|
|
|
}
|
2021-07-08 05:40:27 +00:00
|
|
|
}
|