Skip to content

Commit

Permalink
Merge pull request #106 from Amruth-Vamshi/feature/WA-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ChakshuGautam authored Dec 12, 2024
2 parents 6902c78 + f2412c8 commit d3f9bdd
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 17 deletions.
33 changes: 20 additions & 13 deletions src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ export class ApiController {
@Headers('x-application-id') applicationId?,
): Promise<any> {
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<User> } =
await this.fusionAuthService.getUsersByString(
Expand All @@ -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,
Expand Down Expand Up @@ -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<any> {
return await this.apiService.loginWithOtp(user, authHeader);
}

@Get('verifyOTP')
@UsePipes(new ValidationPipe({ transform: true }))
async verifyOTP(@Query() params: VerifyOtpDto): Promise<any> {
Expand Down Expand Up @@ -400,15 +416,6 @@ export class ApiController {
);
}

@Post('login/otp')
@UsePipes(new ValidationPipe({ transform: true }))
async loginWithOtp(
@Body() user: LoginDto,
@Headers('authorization') authHeader,
): Promise<any> {
return await this.apiService.loginWithOtp(user, authHeader);
}

@Post('login-with-unique-id')
@UsePipes(new ValidationPipe({ transform: true }))
async loginWithUniqueId(
Expand Down
10 changes: 7 additions & 3 deletions src/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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}
Expand Down
6 changes: 5 additions & 1 deletion src/api/dto/login.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
IsNotEmpty, IsString, IsUUID, MaxLength,
IsNotEmpty, IsOptional, IsString, IsUUID, MaxLength,
} from 'class-validator';

export class LoginDto {
Expand All @@ -16,6 +16,10 @@ export class LoginDto {
@IsUUID()
@IsNotEmpty()
applicationId: string;

@IsString()
@IsOptional()
deliveryType?: string;
}


Expand Down
4 changes: 4 additions & 0 deletions src/api/dto/send-otp.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export class SendOtpDto {
@IsString()
@IsOptional()
orgId?: string;

@IsString()
@IsOptional()
deliveryType?: string;
}
1 change: 1 addition & 0 deletions src/user/dto/login.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export class LoginDto {
roles?: Array<string>;
fingerprint?: string;
timestamp?: string;
deliveryType?: string;
}

0 comments on commit d3f9bdd

Please sign in to comment.