chore: add email service and password service
This commit is contained in:
@@ -1 +1 @@
|
||||
export const SMS_CONFIG = "SMS_CONFIG";
|
||||
export const SMS_CONFIG = "SMS_CONFIG";
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
Reference in New Issue
Block a user