diff --git a/src/dst/dst.controller.ts b/src/dst/dst.controller.ts index 16f8ca0..253458a 100644 --- a/src/dst/dst.controller.ts +++ b/src/dst/dst.controller.ts @@ -16,7 +16,8 @@ export class DstController { @UseGuards(AuthGuard('basic')) async sendOTP(@Query('phone') phone): Promise { const status: SMSResponse = await this.otpService.sendOTP(phone); - return { status }; + const resp: SignupResponse = await this.dstService.transformOtpResponse(status); + return { resp }; } @Get('/verifyOTP') diff --git a/src/dst/dst.service.ts b/src/dst/dst.service.ts index f2ee4c8..eb08c15 100644 --- a/src/dst/dst.service.ts +++ b/src/dst/dst.service.ts @@ -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'; @@ -155,4 +155,26 @@ export class DstService { } return response; } + + async transformOtpResponse(status: SMSResponse): Promise { + 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; + } }