forked from Yara724/api
Moved OTP to SMS module
This commit is contained in:
@@ -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 { RegistrarDbService } from "src/users/entities/db-service/registrar.db.service";
|
||||||
import { HashService } from "src/utils/hash/hash.service";
|
import { HashService } from "src/utils/hash/hash.service";
|
||||||
// import { MailService } from "src/utils/mail/mail.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<string, any>, keys: string[]) {
|
function pick(obj: Record<string, any>, keys: string[]) {
|
||||||
const out: Record<string, any> = {};
|
const out: Record<string, any> = {};
|
||||||
@@ -51,7 +51,7 @@ export class ActorAuthService {
|
|||||||
private readonly insurerExpertDbService: InsurerExpertDbService,
|
private readonly insurerExpertDbService: InsurerExpertDbService,
|
||||||
// private readonly mailService: MailService, // Mailer disabled – not used
|
// private readonly mailService: MailService, // Mailer disabled – not used
|
||||||
private readonly clientDbService: ClientDbService,
|
private readonly clientDbService: ClientDbService,
|
||||||
private readonly otpService: OtpService,
|
private readonly otpService: OtpGeneratorService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
// TODO convrt to class for dynamic controller
|
// TODO convrt to class for dynamic controller
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import {
|
|||||||
import { JwtService } from "@nestjs/jwt";
|
import { JwtService } from "@nestjs/jwt";
|
||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import { LoginDtoRs } from "src/auth/dto/user/login.dto";
|
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 { 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 { 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
|
// TODO FIX REGISTER TO USER.SERVICE AND AUTH IN THIS MODULE
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -24,7 +24,7 @@ export class UserAuthService {
|
|||||||
private readonly jwtService: JwtService,
|
private readonly jwtService: JwtService,
|
||||||
private readonly userDbService: UserDbService,
|
private readonly userDbService: UserDbService,
|
||||||
private readonly hashService: HashService,
|
private readonly hashService: HashService,
|
||||||
private readonly otpCreator: OtpService,
|
private readonly otpCreator: OtpGeneratorService,
|
||||||
private readonly smsOrchestrationService: SmsOrchestrationService,
|
private readonly smsOrchestrationService: SmsOrchestrationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { ClientModule } from "src/client/client.module";
|
|||||||
import { UsersModule } from "src/users/users.module";
|
import { UsersModule } from "src/users/users.module";
|
||||||
import { HashModule } from "src/utils/hash/hash.module";
|
import { HashModule } from "src/utils/hash/hash.module";
|
||||||
// import { MailModule } from "src/utils/mail/mail.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";
|
import { SmsOrchestrationModule } from "src/sms-orchestration/sms-orchestration.module";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -20,7 +19,6 @@ import { SmsOrchestrationModule } from "src/sms-orchestration/sms-orchestration.
|
|||||||
UsersModule,
|
UsersModule,
|
||||||
ClientModule,
|
ClientModule,
|
||||||
HashModule,
|
HashModule,
|
||||||
OtpModule,
|
|
||||||
PassportModule,
|
PassportModule,
|
||||||
SmsOrchestrationModule,
|
SmsOrchestrationModule,
|
||||||
JwtModule.register({
|
JwtModule.register({
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
// import crypto from "crypto"
|
|
||||||
const crypto = require("node:crypto");
|
const crypto = require("node:crypto");
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class OtpService {
|
export class OtpGeneratorService {
|
||||||
createDigit(digits: number): string {
|
createDigit(digits: number): string {
|
||||||
const max = Math.pow(10, digits);
|
const max = Math.pow(10, digits);
|
||||||
const randomBytes = crypto.randomBytes(Math.ceil(digits / 2));
|
const randomBytes = crypto.randomBytes(Math.ceil(digits / 2));
|
||||||
const randomNumber = parseInt(randomBytes.toString("hex"), 16) % max;
|
const randomNumber = parseInt(randomBytes.toString("hex"), 16) % max;
|
||||||
return randomNumber.toString().padStart(digits, "0");
|
return randomNumber.toString().padStart(digits, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
create() {
|
create() {
|
||||||
return this.createDigit(5);
|
return this.createDigit(5);
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ import { MongooseModule } from "@nestjs/mongoose";
|
|||||||
import { SmsTextDbService } from "./entities/db-service/sms-text.db.service";
|
import { SmsTextDbService } from "./entities/db-service/sms-text.db.service";
|
||||||
import { SmsText, SmsTextSchema } from "./entities/schema/sms-text.schema";
|
import { SmsText, SmsTextSchema } from "./entities/schema/sms-text.schema";
|
||||||
import { SmsGatewayModule } from "./provider/sms-gateway.module";
|
import { SmsGatewayModule } from "./provider/sms-gateway.module";
|
||||||
|
import { OtpGeneratorService } from "./otp-generator.service";
|
||||||
import { SmsOrchestrationService } from "./sms-orchestration.service";
|
import { SmsOrchestrationService } from "./sms-orchestration.service";
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
@@ -10,7 +11,7 @@ import { SmsOrchestrationService } from "./sms-orchestration.service";
|
|||||||
SmsGatewayModule,
|
SmsGatewayModule,
|
||||||
MongooseModule.forFeature([{ name: SmsText.name, schema: SmsTextSchema }]),
|
MongooseModule.forFeature([{ name: SmsText.name, schema: SmsTextSchema }]),
|
||||||
],
|
],
|
||||||
providers: [SmsTextDbService, SmsOrchestrationService],
|
providers: [SmsTextDbService, SmsOrchestrationService, OtpGeneratorService],
|
||||||
exports: [SmsOrchestrationService],
|
exports: [SmsOrchestrationService, OtpGeneratorService],
|
||||||
})
|
})
|
||||||
export class SmsOrchestrationModule {}
|
export class SmsOrchestrationModule {}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { MongooseModule } from "@nestjs/mongoose";
|
|||||||
import { DamageExpertDbService } from "src/users/entities/db-service/damage-expert.db.service";
|
import { DamageExpertDbService } from "src/users/entities/db-service/damage-expert.db.service";
|
||||||
import { ExpertModel } from "src/users/entities/schema/expert.schema";
|
import { ExpertModel } from "src/users/entities/schema/expert.schema";
|
||||||
import { HashModule } from "src/utils/hash/hash.module";
|
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 { ExpertDbService } from "./entities/db-service/expert.db.service";
|
||||||
import { FieldExpertDbService } from "./entities/db-service/field-expert.db.service";
|
import { FieldExpertDbService } from "./entities/db-service/field-expert.db.service";
|
||||||
import { InsurerExpertDbService } from "./entities/db-service/insurer-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: RegistrarModel.name, schema: RegistrarDbSchema },
|
||||||
{ name: ExpertFileActivity.name, schema: ExpertFileActivitySchema },
|
{ name: ExpertFileActivity.name, schema: ExpertFileActivitySchema },
|
||||||
]),
|
]),
|
||||||
OtpModule,
|
|
||||||
HashModule,
|
HashModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { Module } from "@nestjs/common";
|
|
||||||
import { OtpService } from "./otp.service";
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
providers: [OtpService],
|
|
||||||
exports: [OtpService],
|
|
||||||
})
|
|
||||||
export class OtpModule {}
|
|
||||||
Reference in New Issue
Block a user