Skip to content

Commit

Permalink
Added OTP Response Transformer for DST
Browse files Browse the repository at this point in the history
  • Loading branch information
radhay-samagra committed Apr 29, 2022
1 parent 4e92370 commit 7910aeb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/dst/dst.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export class DstController {
@UseGuards(AuthGuard('basic'))
async sendOTP(@Query('phone') phone): Promise<any> {
const status: SMSResponse = await this.otpService.sendOTP(phone);
return { status };
const resp: SignupResponse = await this.dstService.transformOtpResponse(status);
return { resp };
}

@Get('/verifyOTP')
Expand Down
26 changes: 24 additions & 2 deletions src/dst/dst.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { User } from '@fusionauth/typescript-client';
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { ResponseCode, ResponseStatus, SignupResponse } from './dst.interface';
import { AccountStatus, ResponseCode, ResponseStatus, SignupResponse } from './dst.interface';
import { FusionauthService } from './fusionauth/fusionauth.service';
import { v4 as uuidv4 } from 'uuid';
import { firstValueFrom, map } from 'rxjs';
import { SMSData, SMSResponseStatus, SMSType } from './sms/sms.interface';
import { SMSData, SMSResponse, SMSResponseStatus, SMSType } from './sms/sms.interface';
import { SmsService } from 'src/user/sms/sms.service';
import { UsersResponse } from 'src/user/user.interface';

Expand Down Expand Up @@ -155,4 +155,26 @@ export class DstService {
}
return response;
}

async transformOtpResponse(status: SMSResponse): Promise<SignupResponse> {
console.log({status});

const response: SignupResponse = new SignupResponse().init(uuidv4());
response.responseCode = ResponseCode.OK;
response.params.status = status.status === SMSResponseStatus.failure? ResponseStatus.failure:ResponseStatus.success;
response.params.errMsg = status.error==null?'':status.error.errorText;
response.params.err = status.error==null?'':status.error.errorCode;;
const result = {
responseMsg: status.status,
accountStatus: null,
data: {
phone: status.phone,
networkResponseCode: status.networkResponseCode,
providerResponseCode: status.providerResponseCode,
provider: status.provider
}
}
response.result = result;
return response;
}
}

0 comments on commit 7910aeb

Please sign in to comment.