diff --git a/src/api/api.controller.ts b/src/api/api.controller.ts index ea515e2..2d02fb1 100644 --- a/src/api/api.controller.ts +++ b/src/api/api.controller.ts @@ -80,6 +80,15 @@ export class ApiController { @Headers('x-application-id') applicationId?, ): Promise { let startTime = Date.now(); + + let status: any, isWhatsApp = false, countryCode, number; + + if (params.phone.includes('-')) { + [countryCode, number] = params.phone.split('-'); + params.phone = number; + } else { + number = params.phone; + } if (applicationId) { const { total }: { total: number; users: Array } = await this.fusionAuthService.getUsersByString( @@ -102,12 +111,10 @@ export class ApiController { } } - let status: any, isWhatsApp = false; // Check if phone number contains country code (e.g. 91-1234567890) - if (params.phone.includes('-')) { + if (params.deliveryType=='WA') { isWhatsApp = true; - const [countryCode, number] = params.phone.split('-'); - params.phone = number; + status = await this.gupshupWhatsappService.sendWhatsappOTP({ phone: number, template: null, @@ -136,6 +143,15 @@ export class ApiController { return { status }; } + @Post('login/otp') + @UsePipes(new ValidationPipe({ transform: true })) + async loginWithOtp( + @Body() user: LoginDto, + @Headers('authorization') authHeader, + ): Promise { + return await this.apiService.loginWithOtp(user, authHeader); + } + @Get('verifyOTP') @UsePipes(new ValidationPipe({ transform: true })) async verifyOTP(@Query() params: VerifyOtpDto): Promise { @@ -400,15 +416,6 @@ export class ApiController { ); } - @Post('login/otp') - @UsePipes(new ValidationPipe({ transform: true })) - async loginWithOtp( - @Body() user: LoginDto, - @Headers('authorization') authHeader, - ): Promise { - return await this.apiService.loginWithOtp(user, authHeader); - } - @Post('login-with-unique-id') @UsePipes(new ValidationPipe({ transform: true })) async loginWithUniqueId( diff --git a/src/api/api.service.ts b/src/api/api.service.ts index 87525ba..67bc263 100644 --- a/src/api/api.service.ts +++ b/src/api/api.service.ts @@ -564,6 +564,11 @@ export class ApiService { */ let otp = loginDto.password; let phone = loginDto.loginId; + let countryCode, number; + if (phone.includes('-')) { + [countryCode, number] = phone.split('-'); + phone = number; + } const salt = this.configResolverService.getSalt(loginDto.applicationId); let verifyOTPResult; if( @@ -575,9 +580,8 @@ export class ApiService { verifyOTPResult = {status: SMSResponseStatus.success} else verifyOTPResult = {status: SMSResponseStatus.failure} - } else if (phone.includes('-')) { - const [countryCode, number] = phone.split('-'); - loginDto.loginId = number; + } else if (loginDto.deliveryType=='WA') { + loginDto.loginId = phone; const status: any = await this.gupshupWhatsappService.verifyWhatsappOTP(loginDto.loginId, loginDto.password); if(status.status == 'success') { verifyOTPResult = {status: SMSResponseStatus.success} diff --git a/src/api/dto/login.dto.ts b/src/api/dto/login.dto.ts index 348b9b9..fbe6eee 100644 --- a/src/api/dto/login.dto.ts +++ b/src/api/dto/login.dto.ts @@ -1,5 +1,5 @@ import { - IsNotEmpty, IsString, IsUUID, MaxLength, + IsNotEmpty, IsOptional, IsString, IsUUID, MaxLength, } from 'class-validator'; export class LoginDto { @@ -16,6 +16,10 @@ export class LoginDto { @IsUUID() @IsNotEmpty() applicationId: string; + + @IsString() + @IsOptional() + deliveryType?: string; } diff --git a/src/api/dto/send-otp.dto.ts b/src/api/dto/send-otp.dto.ts index e3dc1a0..791448a 100644 --- a/src/api/dto/send-otp.dto.ts +++ b/src/api/dto/send-otp.dto.ts @@ -19,4 +19,8 @@ export class SendOtpDto { @IsString() @IsOptional() orgId?: string; + + @IsString() + @IsOptional() + deliveryType?: string; } diff --git a/src/user/dto/login.dto.ts b/src/user/dto/login.dto.ts index 503d67c..6c3a3d8 100644 --- a/src/user/dto/login.dto.ts +++ b/src/user/dto/login.dto.ts @@ -7,4 +7,5 @@ export class LoginDto { roles?: Array; fingerprint?: string; timestamp?: string; + deliveryType?: string; }