-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43d77d3
commit 3cff959
Showing
4 changed files
with
48 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import { Body, Controller, Post } from '@nestjs/common'; | ||
import { GenrateOtpService } from './genrateOtp.service'; | ||
import { OtpDto } from './dto/genrateOtp.dto'; | ||
import { OtpDto, VerifyOtpDto } from './dto/genrateOtp.dto'; | ||
import { Public } from '../auth/decorators/public.decorator'; | ||
|
||
@Controller('generate-OTP') | ||
@Controller('otp') | ||
export class GenerateOtpController { | ||
constructor(private readonly genrateOtpService: GenrateOtpService) {} | ||
|
||
@Public() | ||
@Post() | ||
@Post('generate') | ||
async create(@Body() genrateOtpDto: OtpDto) { | ||
return await this.genrateOtpService.enqueueOtpJob(genrateOtpDto); | ||
} | ||
|
||
@Public() | ||
@Post('verify') | ||
async verify(@Body() verifyOtpDto: VerifyOtpDto) { | ||
return (await this.genrateOtpService.compareOtp(verifyOtpDto)) | ||
? 'OTP is correct' | ||
: 'OTP is incorrect'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { OtpProducer } from 'src/services/bullmq/producers/otp.producer'; | ||
import { OtpDto } from './dto/genrateOtp.dto'; | ||
import { OtpDto, VerifyOtpDto } from './dto/genrateOtp.dto'; | ||
import { processEmail } from './genrateOtp.helper'; | ||
import { OtpQueueProcessor } from 'src/services/bullmq/processors/otp.processor'; | ||
|
||
@Injectable() | ||
export class GenrateOtpService { | ||
constructor(private readonly otpProducer: OtpProducer) {} | ||
constructor( | ||
private readonly otpProducer: OtpProducer, | ||
private readonly processor: OtpQueueProcessor, | ||
) {} | ||
|
||
async enqueueOtpJob(createOtpDto: OtpDto) { | ||
const email = processEmail(createOtpDto); | ||
await this.otpProducer.pushForAsyncStream(`process-otp`, email, { | ||
removeOnComplete: true, | ||
}); | ||
} | ||
|
||
async compareOtp(verifyOtpDto: VerifyOtpDto): Promise<boolean> { | ||
return await this.processor.comapreOtp( | ||
verifyOtpDto.email, | ||
verifyOtpDto.otp, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters