import { UseGuards , UsePipes } from '@nestjs/common' ; import { Args , Context , Mutation , Resolver } from '@nestjs/graphql' ; import { GenerateOtpInput , RefreshTokenInput , TokenResponse , UserOTPLoginInput , UserPasswordLoginInput , UserPasswordSignupInput , UserSignupResponse , } from '../../schema/graphql.schema' ; import User from '../../authorization/entity/user.entity' ; import { AuthGuard } from '../authentication.guard' ; import { GenerateOtpInputSchema , UserOTPLoginInputSchema , UserOTPSignupInputSchema , UserPasswordInputSchema , UserPasswordLoginInputSchema , UserPasswordSignupInputSchema , } from '../validation/user.auth.schema.validation' ; import ValidationPipe from '../../validation/validation.pipe' ; import PasswordAuthService from '../service/password.auth.service' ; import OTPAuthService from '../service/otp.auth.service' ; import { TokenService } from '../service/token.service' ; @ Resolver ( 'Userauth' ) export default class UserAuthResolver { constructor ( private readonly passwordAuthService , private readonly otpAuthService , private readonly tokenService ) { } @ Mutation ( 'passwordLogin' ) async passwordLogin ( @ Args ( 'input' , new ValidationPipe ( UserPasswordLoginInputSchema ) ) request ) { return this . passwordAuthService . userLogin ( request ) ; } @ Mutation ( 'passwordSignup' ) async passwordSignup ( @ Args ( 'input' , new ValidationPipe ( UserPasswordSignupInputSchema ) ) request ) { return this . passwordAuthService . userSignup ( request ) ; } @ Mutation ( 'otpLogin' ) @ UsePipes ( new ValidationPipe ( UserOTPLoginInputSchema ) ) async otpLogin ( @ Args ( 'input' ) request ) { return this . otpAuthService . userLogin ( request ) ; } @ Mutation ( 'otpSignup' ) @ UsePipes ( new ValidationPipe ( UserOTPSignupInputSchema ) ) async otpSignup ( @ Args ( 'input' ) request ) { return this . otpAuthService . userSignup ( request ) ; } @ Mutation ( 'changePassword' ) @ UseGuards ( AuthGuard ) async changeUserPassword ( @ Args ( 'input' , new ValidationPipe ( UserPasswordInputSchema ) ) request , @ Context ( 'user' ) user ) { return this . passwordAuthService . updatePassword ( user . id , request ) ; } @ Mutation ( 'refresh' ) async refresh ( @ Args ( 'input' ) request ) { return this . tokenService . refresh ( request . refreshToken ) ; } @ Mutation ( 'logout' ) @ UseGuards ( AuthGuard ) async logout ( @ Context ( 'user' ) user ) { return this . tokenService . resetToken ( user . id ) ; } @ Mutation ( 'generateOtp' ) @ UsePipes ( new ValidationPipe ( GenerateOtpInputSchema ) ) async generateOtp ( @ Args ( 'input' ) request ) { return this . otpAuthService . sendOTP ( request . phone ) ; } }