ToolJet/server/src/controllers/app.controller.ts

48 lines
1.6 KiB
TypeScript
Raw Normal View History

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';
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
@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')
async signup(@Body() appAuthDto: AppAuthenticationDto) {
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')
async forgotPassword(@Body() appAuthDto: AppForgotPasswordDto) {
await this.authService.forgotPassword(appAuthDto.email);
return {};
2021-07-26 16:02:47 +00:00
}
@Post('/reset_password')
async resetPassword(@Body() appAuthDto: AppPasswordResetDto) {
const { token, password } = appAuthDto;
2021-07-26 16:02:47 +00:00
await this.authService.resetPassword(token, password);
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
}