Skip to content

Commit d3f9bdd

Browse files
Merge pull request #106 from Amruth-Vamshi/feature/WA-provider
2 parents 6902c78 + f2412c8 commit d3f9bdd

File tree

5 files changed

+37
-17
lines changed

5 files changed

+37
-17
lines changed

src/api/api.controller.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ export class ApiController {
8080
@Headers('x-application-id') applicationId?,
8181
): Promise<any> {
8282
let startTime = Date.now();
83+
84+
let status: any, isWhatsApp = false, countryCode, number;
85+
86+
if (params.phone.includes('-')) {
87+
[countryCode, number] = params.phone.split('-');
88+
params.phone = number;
89+
} else {
90+
number = params.phone;
91+
}
8392
if (applicationId) {
8493
const { total }: { total: number; users: Array<User> } =
8594
await this.fusionAuthService.getUsersByString(
@@ -102,12 +111,10 @@ export class ApiController {
102111
}
103112
}
104113

105-
let status: any, isWhatsApp = false;
106114
// Check if phone number contains country code (e.g. 91-1234567890)
107-
if (params.phone.includes('-')) {
115+
if (params.deliveryType=='WA') {
108116
isWhatsApp = true;
109-
const [countryCode, number] = params.phone.split('-');
110-
params.phone = number;
117+
111118
status = await this.gupshupWhatsappService.sendWhatsappOTP({
112119
phone: number,
113120
template: null,
@@ -136,6 +143,15 @@ export class ApiController {
136143
return { status };
137144
}
138145

146+
@Post('login/otp')
147+
@UsePipes(new ValidationPipe({ transform: true }))
148+
async loginWithOtp(
149+
@Body() user: LoginDto,
150+
@Headers('authorization') authHeader,
151+
): Promise<any> {
152+
return await this.apiService.loginWithOtp(user, authHeader);
153+
}
154+
139155
@Get('verifyOTP')
140156
@UsePipes(new ValidationPipe({ transform: true }))
141157
async verifyOTP(@Query() params: VerifyOtpDto): Promise<any> {
@@ -400,15 +416,6 @@ export class ApiController {
400416
);
401417
}
402418

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-
412419
@Post('login-with-unique-id')
413420
@UsePipes(new ValidationPipe({ transform: true }))
414421
async loginWithUniqueId(

src/api/api.service.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ export class ApiService {
564564
*/
565565
let otp = loginDto.password;
566566
let phone = loginDto.loginId;
567+
let countryCode, number;
568+
if (phone.includes('-')) {
569+
[countryCode, number] = phone.split('-');
570+
phone = number;
571+
}
567572
const salt = this.configResolverService.getSalt(loginDto.applicationId);
568573
let verifyOTPResult;
569574
if(
@@ -575,9 +580,8 @@ export class ApiService {
575580
verifyOTPResult = {status: SMSResponseStatus.success}
576581
else
577582
verifyOTPResult = {status: SMSResponseStatus.failure}
578-
} else if (phone.includes('-')) {
579-
const [countryCode, number] = phone.split('-');
580-
loginDto.loginId = number;
583+
} else if (loginDto.deliveryType=='WA') {
584+
loginDto.loginId = phone;
581585
const status: any = await this.gupshupWhatsappService.verifyWhatsappOTP(loginDto.loginId, loginDto.password);
582586
if(status.status == 'success') {
583587
verifyOTPResult = {status: SMSResponseStatus.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)