diff --git a/src/auth/auth-services/actor.auth.service.ts b/src/auth/auth-services/actor.auth.service.ts index e37a58b..41d0655 100644 --- a/src/auth/auth-services/actor.auth.service.ts +++ b/src/auth/auth-services/actor.auth.service.ts @@ -28,7 +28,7 @@ import { FieldExpertDbService } from "src/users/entities/db-service/field-expert import { RegistrarDbService } from "src/users/entities/db-service/registrar.db.service"; import { HashService } from "src/utils/hash/hash.service"; // import { MailService } from "src/utils/mail/mail.service"; -import { OtpService } from "src/utils/otp/otp.service"; +import { OtpGeneratorService } from "src/sms-orchestration/otp-generator.service"; function pick(obj: Record, keys: string[]) { const out: Record = {}; @@ -51,7 +51,7 @@ export class ActorAuthService { private readonly insurerExpertDbService: InsurerExpertDbService, // private readonly mailService: MailService, // Mailer disabled – not used private readonly clientDbService: ClientDbService, - private readonly otpService: OtpService, + private readonly otpService: OtpGeneratorService, ) {} // TODO convrt to class for dynamic controller diff --git a/src/auth/auth-services/user.auth.service.ts b/src/auth/auth-services/user.auth.service.ts index 6aea3fd..35246d1 100644 --- a/src/auth/auth-services/user.auth.service.ts +++ b/src/auth/auth-services/user.auth.service.ts @@ -10,10 +10,10 @@ import { import { JwtService } from "@nestjs/jwt"; import { Types } from "mongoose"; import { LoginDtoRs } from "src/auth/dto/user/login.dto"; +import { OtpGeneratorService } from "src/sms-orchestration/otp-generator.service"; import { UserDbService } from "src/users/entities/db-service/user.db.service"; -import { HashService } from "src/utils/hash/hash.service"; -import { OtpService } from "src/utils/otp/otp.service"; import { SmsOrchestrationService } from "src/sms-orchestration/sms-orchestration.service"; +import { HashService } from "src/utils/hash/hash.service"; // TODO FIX REGISTER TO USER.SERVICE AND AUTH IN THIS MODULE @Injectable() @@ -24,7 +24,7 @@ export class UserAuthService { private readonly jwtService: JwtService, private readonly userDbService: UserDbService, private readonly hashService: HashService, - private readonly otpCreator: OtpService, + private readonly otpCreator: OtpGeneratorService, private readonly smsOrchestrationService: SmsOrchestrationService, ) {} diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index 34b25e4..5eee53e 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -11,7 +11,6 @@ import { ClientModule } from "src/client/client.module"; import { UsersModule } from "src/users/users.module"; import { HashModule } from "src/utils/hash/hash.module"; // import { MailModule } from "src/utils/mail/mail.module"; -import { OtpModule } from "src/utils/otp/otp.module"; import { SmsOrchestrationModule } from "src/sms-orchestration/sms-orchestration.module"; @Module({ @@ -20,7 +19,6 @@ import { SmsOrchestrationModule } from "src/sms-orchestration/sms-orchestration. UsersModule, ClientModule, HashModule, - OtpModule, PassportModule, SmsOrchestrationModule, JwtModule.register({ diff --git a/src/utils/otp/otp.service.ts b/src/sms-orchestration/otp-generator.service.ts similarity index 88% rename from src/utils/otp/otp.service.ts rename to src/sms-orchestration/otp-generator.service.ts index 70ef6df..417a416 100644 --- a/src/utils/otp/otp.service.ts +++ b/src/sms-orchestration/otp-generator.service.ts @@ -1,15 +1,15 @@ import { Injectable } from "@nestjs/common"; -// import crypto from "crypto" const crypto = require("node:crypto"); @Injectable() -export class OtpService { +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); } diff --git a/src/sms-orchestration/sms-orchestration.module.ts b/src/sms-orchestration/sms-orchestration.module.ts index bcc1d20..e68d836 100644 --- a/src/sms-orchestration/sms-orchestration.module.ts +++ b/src/sms-orchestration/sms-orchestration.module.ts @@ -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 {} diff --git a/src/users/users.module.ts b/src/users/users.module.ts index db86804..12e7e04 100644 --- a/src/users/users.module.ts +++ b/src/users/users.module.ts @@ -3,7 +3,6 @@ import { MongooseModule } from "@nestjs/mongoose"; import { DamageExpertDbService } from "src/users/entities/db-service/damage-expert.db.service"; import { ExpertModel } from "src/users/entities/schema/expert.schema"; import { HashModule } from "src/utils/hash/hash.module"; -import { OtpModule } from "src/utils/otp/otp.module"; import { ExpertDbService } from "./entities/db-service/expert.db.service"; import { FieldExpertDbService } from "./entities/db-service/field-expert.db.service"; import { InsurerExpertDbService } from "./entities/db-service/insurer-expert.db.service"; @@ -44,7 +43,6 @@ import { UserModel, UserDbSchema } from "./entities/schema/user.schema"; { name: RegistrarModel.name, schema: RegistrarDbSchema }, { name: ExpertFileActivity.name, schema: ExpertFileActivitySchema }, ]), - OtpModule, HashModule, ], controllers: [], diff --git a/src/utils/otp/otp.module.ts b/src/utils/otp/otp.module.ts deleted file mode 100644 index ab986ca..0000000 --- a/src/utils/otp/otp.module.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { Module } from "@nestjs/common"; -import { OtpService } from "./otp.service"; - -@Module({ - providers: [OtpService], - exports: [OtpService], -}) -export class OtpModule {}