import { HttpCode , Inject , Controller , Body , Post , UseGuards , UseFilters , Put , Param , ParseIntPipe , ValidationPipe , Get , HttpStatus , } from "@nestjs/common" ; import { UserDto } from "../user" ; import { AuthDiToken } from "./auth.di" ; import { RoleWildcard } from "../db" ; import { Authorize , Public } from "./decorators" ; import { UserUpdatePasswordDto } from "../user/dto" ; import { ValidationExceptionFilter } from "../../http/filters" ; import { InvalidPasswordExceptionFilter } from "./filters/invalid-password.exception-filter" ; import { AuthService , CurrentUserService } from "./services" ; import { AuthorizeGuard , PermissionWildcard } from "./guards" ; import { PermissionService , PermissionDiToken } from "./permission" ; import { UserLoginDto , ResendInviteDto , ResetPasswordDto } from "./auth.interfaces" ; import { UserRegistrationDto , RoleDto , AclDto , AclDashboardDto , RolePermissionDto } from "./dto" ; @ Controller ( "/auth" ) @ UseGuards ( AuthorizeGuard ) @ UseFilters ( InvalidPasswordExceptionFilter , ValidationExceptionFilter ) export class AuthController { public constructor ( @ Inject ( AuthDiToken . AUTH_SERVICE ) private readonly authService , @ Inject ( AuthDiToken . CURRENT_USER_SERVICE ) private readonly currentUserService , @ Inject ( PermissionDiToken . PERMISSION_SERVICE ) private readonly permissionService ) { } @ HttpCode ( HttpStatus . OK ) @ Post ( "/login" ) @ Public ( ) public async login ( @ Body ( ) userInfo ) { return this . authService . login ( userInfo ) ; } @ HttpCode ( HttpStatus . OK ) @ Post ( "/invite/verify" ) @ Public ( ) public async verifyInvite ( @ Body ( "token" ) token ) { return this . authService . verifyInvite ( token ) ; } @ Get ( "/role" ) public async getRoles ( ) { return this . authService . getRoles ( ) ; } @ HttpCode ( HttpStatus . OK ) @ Get ( "/acl" ) @ Authorize ( { [ RoleWildcard ] : PermissionWildcard } ) public async getACL ( ) { return this . permissionService . getACL ( this . currentUserService . get ( ) ) ; } @ HttpCode ( HttpStatus . OK ) @ Get ( "/acl/dashboard" ) @ Authorize ( ) public async getRolesACLDashboard ( ) { return this . permissionService . getACLDashboard ( ) ; } @ HttpCode ( HttpStatus . NO_CONTENT ) @ Put ( "/acl" ) @ Authorize ( ) public async updateRolePermission ( @ Body ( ) data ) { return this . permissionService . updateRolePermission ( data ) ; } @ HttpCode ( HttpStatus . OK ) @ Post ( "/invite/resend" ) @ Public ( ) public async resendInvite ( @ Body ( ) data ) { return this . authService . resendInviteEmail ( data ) ; } @ HttpCode ( HttpStatus . OK ) @ Post ( "/register" ) @ Public ( ) public async register ( @ Body ( new ValidationPipe ( { transform : true } ) ) data ) { return this . authService . register ( data ) ; } @ HttpCode ( HttpStatus . OK ) @ Post ( "/password/reset" ) @ Public ( ) public async resetPassword ( @ Body ( ) data ) { return this . authService . sendResetPasswordEmail ( data ) ; } @ HttpCode ( HttpStatus . OK ) @ Post ( "/password/reset/verify" ) @ Public ( ) public async verifyResetPassword ( @ Body ( "token" ) token ) { return this . authService . verifyResetPassword ( token ) ; } @ Put ( "/user/:id/password" ) public updatePassword ( @ Body ( ) data , @ Param ( "id" , new ParseIntPipe ( ) ) id ) { return this . authService . updatePassword ( id , data ) ; } }