Unverified Commit b9978a16 authored by Abhishek Mishra's avatar Abhishek Mishra Committed by GitHub
Browse files

Merge pull request #61 from choxx/user-otp-validation

SendOTP: verifying from db if user exists or not before sending OTP i…
No related merge requests found
Showing with 19 additions and 2 deletions
+19 -2
......@@ -7,7 +7,7 @@ import {
Param,
Patch,
Post,
Query,
Query, UnprocessableEntityException,
} from '@nestjs/common';
import {
SignupResponse,
......@@ -44,7 +44,24 @@ export class ApiController {
}
@Get('sendOTP')
async sendOTP(@Query('phone') phone): Promise<any> {
async sendOTP(
@Query('phone') phone,
@Query('errorMessage') errorMessage = 'User not found.',
@Headers('x-application-id') applicationId?,
): Promise<any> {
if (applicationId) {
const { total }: { total: number; users: Array<User> } =
await this.fusionAuthService.getUsersByString(
`(username: ${phone}, mobilePhone: ${phone})`,
0,
1,
applicationId,
null,
);
if (!total || total == 0) {
throw new UnprocessableEntityException(errorMessage);
}
}
const status: SMSResponse = await this.otpService.sendOTP(phone);
return { status };
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment