chore: add email service and password service

This commit is contained in:
mahyargdz
2025-01-20 09:13:27 +03:30
parent 7347a696d0
commit 9701c51445
18 changed files with 10575 additions and 24 deletions
+1 -1
View File
@@ -1 +1 @@
export const SMS_CONFIG = "SMS_CONFIG";
export const SMS_CONFIG = "SMS_CONFIG";
+11 -11
View File
@@ -1,18 +1,18 @@
export interface ISmsBody {
ParameterArray: IParameterArray[];
Mobile: string;
TemplateId: string;
UserApiKey: string;
SecretKey: string;
ParameterArray: IParameterArray[];
Mobile: string;
TemplateId: string;
UserApiKey: string;
SecretKey: string;
}
export interface IParameterArray {
Parameter: string;
ParameterValue: string;
Parameter: string;
ParameterValue: string;
}
export interface ISmsResponse {
VerificationCodeId: number;
isSuccessful: boolean;
Message: string;
}
VerificationCodeId: number;
isSuccessful: boolean;
Message: string;
}
@@ -0,0 +1,25 @@
import { Injectable, Logger } from "@nestjs/common";
import { MailerService } from "@nestjs-modules/mailer";
@Injectable()
export class EmailService {
private readonly logger = new Logger(EmailService.name);
constructor(private readonly mailerService: MailerService) {}
async sendEmail(to: string, subject: string) {
try {
await this.mailerService.sendMail({
to: to,
from: "noreply@nestjs.com",
subject: subject,
template: "otp",
context: {
//Data to be sent to template
},
});
} catch (error) {
this.logger.error("Email sending failed:", error);
return false;
}
}
}
@@ -1,6 +1,14 @@
import { Injectable } from "@nestjs/common";
import { compare, genSalt, hash } from "bcrypt";
@Injectable()
export class PasswordService {
async hashPassword(rawPassword: string) {}
//** */
async hashPassword(rawPassword: string) {
const salt = await genSalt(10);
return hash(rawPassword, salt);
}
//** */
async comparePassword(rawPassword: string, hashedPassword: string) {
return compare(rawPassword, hashedPassword);
}
}
@@ -1,5 +1,6 @@
import { Inject, Injectable, Logger } from "@nestjs/common";
import axios from "axios";
import { ISmsConfigs } from "../../../configs/sms.config";
import { SMS_CONFIG } from "../constants";
import { ISmsBody } from "../interfaces/ISms";
+5 -1
View File
@@ -3,18 +3,22 @@ import { Module } from "@nestjs/common";
import { SMS_CONFIG } from "./constants";
import { CacheService } from "./providers/cache.service";
import { OTPService } from "./providers/otp.service";
import { PasswordService } from "./providers/password.service";
import { SmsService } from "./providers/sms.service";
import { SmsConfigs } from "../../configs/sms.config";
@Module({
providers: [
OTPService,
PasswordService,
CacheService,
SmsService,
{
provide: SMS_CONFIG,
useFactory: SmsConfigs().useFactory,
inject: SmsConfigs().inject,
},
],
exports: [SMS_CONFIG],
exports: [SMS_CONFIG, OTPService, PasswordService, CacheService, SmsService],
})
export class UtilsModule {}