mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
feat: handle notification async using event emitter
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { NotificationsService } from '../../notification/services/notifications.service';
|
||||
import { DEFAULT_OTP_DIGIT, DEFAULT_OTP_LENGTH } from '../constants';
|
||||
import { OtpType } from '../enums';
|
||||
import { ISendOtp, IVerifyOtp } from '../interfaces';
|
||||
@ -8,7 +9,11 @@ import { generateRandomOtp } from '../utils';
|
||||
|
||||
@Injectable()
|
||||
export class OtpService {
|
||||
constructor(private readonly configService: ConfigService, private readonly otpRepository: OtpRepository) {}
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
private readonly otpRepository: OtpRepository,
|
||||
private readonly notificationService: NotificationsService,
|
||||
) {}
|
||||
private useMock = this.configService.get<boolean>('USE_MOCK', false);
|
||||
async generateAndSendOtp(sendotpRequest: ISendOtp): Promise<string> {
|
||||
const otp = this.useMock ? DEFAULT_OTP_DIGIT.repeat(DEFAULT_OTP_LENGTH) : generateRandomOtp(DEFAULT_OTP_LENGTH);
|
||||
@ -28,8 +33,7 @@ export class OtpService {
|
||||
return !!otp;
|
||||
}
|
||||
|
||||
private sendOtp(sendotpRequest: ISendOtp, otp: string) {
|
||||
// TODO: send OTP to the user
|
||||
return;
|
||||
private sendOtp(sendOtpRequest: ISendOtp, otp: string) {
|
||||
return this.notificationService.sendOtpNotification(sendOtpRequest, otp);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user