Skip to content

Commit 6590e48

Browse files
committed
Updated sendOTP logic
1 parent be685a9 commit 6590e48

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

src/api/api.controller.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,15 @@ export class ApiController {
102102
}
103103
}
104104

105-
let status: any, isWhatsApp = false;
105+
let status: any, isWhatsApp = false, countryCode, number;
106106
// Check if phone number contains country code (e.g. 91-1234567890)
107-
if (params.phone.includes('-')) {
107+
if (params.deliveryType=='WA') {
108108
isWhatsApp = true;
109-
const [countryCode, number] = params.phone.split('-');
109+
if (params.phone.includes('-')) {
110+
[countryCode, number] = params.phone.split('-');
111+
} else {
112+
number = params.phone;
113+
}
110114
params.phone = number;
111115
status = await this.gupshupWhatsappService.sendWhatsappOTP({
112116
phone: number,
@@ -136,6 +140,15 @@ export class ApiController {
136140
return { status };
137141
}
138142

143+
@Post('login/otp')
144+
@UsePipes(new ValidationPipe({ transform: true }))
145+
async loginWithOtp(
146+
@Body() user: LoginDto,
147+
@Headers('authorization') authHeader,
148+
): Promise<any> {
149+
return await this.apiService.loginWithOtp(user, authHeader);
150+
}
151+
139152
@Get('verifyOTP')
140153
@UsePipes(new ValidationPipe({ transform: true }))
141154
async verifyOTP(@Query() params: VerifyOtpDto): Promise<any> {
@@ -400,15 +413,6 @@ export class ApiController {
400413
);
401414
}
402415

403-
@Post('login/otp')
404-
@UsePipes(new ValidationPipe({ transform: true }))
405-
async loginWithOtp(
406-
@Body() user: LoginDto,
407-
@Headers('authorization') authHeader,
408-
): Promise<any> {
409-
return await this.apiService.loginWithOtp(user, authHeader);
410-
}
411-
412416
@Post('login-with-unique-id')
413417
@UsePipes(new ValidationPipe({ transform: true }))
414418
async loginWithUniqueId(

src/api/api.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ export class ApiService {
564564
*/
565565
let otp = loginDto.password;
566566
let phone = loginDto.loginId;
567+
let countryCode, number;
567568
const salt = this.configResolverService.getSalt(loginDto.applicationId);
568569
let verifyOTPResult;
569570
if(
@@ -575,8 +576,12 @@ export class ApiService {
575576
verifyOTPResult = {status: SMSResponseStatus.success}
576577
else
577578
verifyOTPResult = {status: SMSResponseStatus.failure}
578-
} else if (phone.includes('-')) {
579-
const [countryCode, number] = phone.split('-');
579+
} else if (loginDto.deliveryType=='WA') {
580+
if(phone.includes('-')){
581+
[countryCode, number] = phone.split('-');
582+
} else {
583+
number = phone
584+
}
580585
loginDto.loginId = number;
581586
const status: any = await this.gupshupWhatsappService.verifyWhatsappOTP(loginDto.loginId, loginDto.password);
582587
if(status.status == 'success') {

src/api/dto/login.dto.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
IsNotEmpty, IsString, IsUUID, MaxLength,
2+
IsNotEmpty, IsOptional, IsString, IsUUID, MaxLength,
33
} from 'class-validator';
44

55
export class LoginDto {
@@ -16,6 +16,10 @@ export class LoginDto {
1616
@IsUUID()
1717
@IsNotEmpty()
1818
applicationId: string;
19+
20+
@IsString()
21+
@IsOptional()
22+
deliveryType?: string;
1923
}
2024

2125

src/api/dto/send-otp.dto.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ export class SendOtpDto {
1919
@IsString()
2020
@IsOptional()
2121
orgId?: string;
22+
23+
@IsString()
24+
@IsOptional()
25+
deliveryType?: string;
2226
}

src/user/dto/login.dto.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export class LoginDto {
77
roles?: Array<string>;
88
fingerprint?: string;
99
timestamp?: string;
10+
deliveryType?: string;
1011
}

0 commit comments

Comments
 (0)