forked from Yara724/api
Moved OTP to SMS module
This commit is contained in:
16
src/sms-orchestration/otp-generator.service.ts
Normal file
16
src/sms-orchestration/otp-generator.service.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Injectable } from "@nestjs/common";
|
||||
const crypto = require("node:crypto");
|
||||
|
||||
@Injectable()
|
||||
export class OtpGeneratorService {
|
||||
createDigit(digits: number): string {
|
||||
const max = Math.pow(10, digits);
|
||||
const randomBytes = crypto.randomBytes(Math.ceil(digits / 2));
|
||||
const randomNumber = parseInt(randomBytes.toString("hex"), 16) % max;
|
||||
return randomNumber.toString().padStart(digits, "0");
|
||||
}
|
||||
|
||||
create() {
|
||||
return this.createDigit(5);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { MongooseModule } from "@nestjs/mongoose";
|
||||
import { SmsTextDbService } from "./entities/db-service/sms-text.db.service";
|
||||
import { SmsText, SmsTextSchema } from "./entities/schema/sms-text.schema";
|
||||
import { SmsGatewayModule } from "./provider/sms-gateway.module";
|
||||
import { OtpGeneratorService } from "./otp-generator.service";
|
||||
import { SmsOrchestrationService } from "./sms-orchestration.service";
|
||||
|
||||
@Module({
|
||||
@@ -10,7 +11,7 @@ import { SmsOrchestrationService } from "./sms-orchestration.service";
|
||||
SmsGatewayModule,
|
||||
MongooseModule.forFeature([{ name: SmsText.name, schema: SmsTextSchema }]),
|
||||
],
|
||||
providers: [SmsTextDbService, SmsOrchestrationService],
|
||||
exports: [SmsOrchestrationService],
|
||||
providers: [SmsTextDbService, SmsOrchestrationService, OtpGeneratorService],
|
||||
exports: [SmsOrchestrationService, OtpGeneratorService],
|
||||
})
|
||||
export class SmsOrchestrationModule {}
|
||||
|
||||
Reference in New Issue
Block a user