chore: change the login and regitster flow to single route
This commit is contained in:
@@ -7,6 +7,7 @@ export { NotificationHandlerFactory } from "./notification-handler.factory";
|
||||
// Special handlers (non-transactional)
|
||||
export { OtpHandler } from "./otp.handler";
|
||||
export { UserLoginHandler } from "./user-login.handler";
|
||||
export { UserPasswordHandler } from "./user-password.handler";
|
||||
|
||||
// Wallet handlers
|
||||
export { WalletChargeHandler, WalletDeductionHandler } from "./wallet.handler";
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { PaymentCancellationHandler, PaymentReminderHandler } from "./payment.handler";
|
||||
import { BlockServiceHandler } from "./service.handler";
|
||||
import { AnswerTicketHandler, AssignTicketHandler, CreateTicketHandler, NewTicketHandler } from "./ticket.handler";
|
||||
import { UserPasswordHandler } from "./user-password.handler";
|
||||
import { WalletChargeHandler, WalletDeductionHandler } from "./wallet.handler";
|
||||
import { NotifType } from "../../settings/enums/notif-settings.enum";
|
||||
|
||||
@@ -25,11 +26,9 @@ export class NotificationHandlerFactory {
|
||||
private readonly handlers: Map<NotifType, BaseNotificationHandler> = new Map();
|
||||
|
||||
constructor(
|
||||
// Wallet handlers
|
||||
private readonly walletChargeHandler: WalletChargeHandler,
|
||||
private readonly walletDeductionHandler: WalletDeductionHandler,
|
||||
|
||||
// Invoice handlers
|
||||
private readonly createInvoiceHandler: CreateInvoiceHandler,
|
||||
private readonly billInvoiceReminderHandler: BillInvoiceReminderHandler,
|
||||
private readonly billInvoiceHandler: BillInvoiceHandler,
|
||||
@@ -37,7 +36,6 @@ export class NotificationHandlerFactory {
|
||||
private readonly invoiceOverdueHandler: InvoiceOverdueHandler,
|
||||
private readonly recurringInvoiceHandler: RecurringInvoiceHandler,
|
||||
|
||||
// Admin handlers
|
||||
private readonly blogCommentHandler: BlogCommentHandler,
|
||||
private readonly serviceReviewHandler: ServiceReviewHandler,
|
||||
private readonly newCustomerHandler: NewCustomerHandler,
|
||||
@@ -45,30 +43,26 @@ export class NotificationHandlerFactory {
|
||||
private readonly newCriticismHandler: NewCriticismHandler,
|
||||
private readonly newTicketHandler: NewTicketHandler,
|
||||
|
||||
// User handlers
|
||||
private readonly announcementHandler: AnnouncementHandler,
|
||||
|
||||
// Ticket handlers
|
||||
private readonly answerTicketHandler: AnswerTicketHandler,
|
||||
private readonly createTicketHandler: CreateTicketHandler,
|
||||
private readonly assignTicketHandler: AssignTicketHandler,
|
||||
|
||||
// Service handlers
|
||||
private readonly blockServiceHandler: BlockServiceHandler,
|
||||
|
||||
// Payment handlers
|
||||
private readonly paymentReminderHandler: PaymentReminderHandler,
|
||||
private readonly paymentCancellationHandler: PaymentCancellationHandler,
|
||||
|
||||
private readonly userPasswordHandler: UserPasswordHandler,
|
||||
) {
|
||||
this.registerHandlers();
|
||||
}
|
||||
|
||||
private registerHandlers(): void {
|
||||
// Wallet notifications
|
||||
this.handlers.set(NotifType.WALLET_CHARGE, this.walletChargeHandler);
|
||||
this.handlers.set(NotifType.WALLET_DEDUCTION, this.walletDeductionHandler);
|
||||
|
||||
// Invoice notifications
|
||||
this.handlers.set(NotifType.CREATE_INVOICE, this.createInvoiceHandler);
|
||||
this.handlers.set(NotifType.BILL_INVOICE_REMINDER, this.billInvoiceReminderHandler);
|
||||
this.handlers.set(NotifType.BILL_INVOICE, this.billInvoiceHandler);
|
||||
@@ -76,7 +70,6 @@ export class NotificationHandlerFactory {
|
||||
this.handlers.set(NotifType.INVOICE_OVERDUE, this.invoiceOverdueHandler);
|
||||
this.handlers.set(NotifType.RECURRING_INVOICE, this.recurringInvoiceHandler);
|
||||
|
||||
// Admin notifications
|
||||
this.handlers.set(NotifType.NEW_BLOG_COMMENT, this.blogCommentHandler);
|
||||
this.handlers.set(NotifType.NEW_SERVICE_REVIEW, this.serviceReviewHandler);
|
||||
this.handlers.set(NotifType.NEW_CUSTOMER, this.newCustomerHandler);
|
||||
@@ -84,21 +77,19 @@ export class NotificationHandlerFactory {
|
||||
this.handlers.set(NotifType.NEW_CRITICISM, this.newCriticismHandler);
|
||||
this.handlers.set(NotifType.NEW_TICKET, this.newTicketHandler);
|
||||
|
||||
// User notifications
|
||||
this.handlers.set(NotifType.ANNOUNCEMENT, this.announcementHandler);
|
||||
|
||||
// Ticket notifications
|
||||
this.handlers.set(NotifType.ANSWER_TICKET, this.answerTicketHandler);
|
||||
this.handlers.set(NotifType.CREATE_TICKET, this.createTicketHandler);
|
||||
this.handlers.set(NotifType.ASSIGN_TICKET, this.assignTicketHandler);
|
||||
|
||||
// Service notifications
|
||||
this.handlers.set(NotifType.BLOCK_SERVICE, this.blockServiceHandler);
|
||||
|
||||
// Payment notifications
|
||||
this.handlers.set(NotifType.PAYMENT_REMINDER, this.paymentReminderHandler);
|
||||
this.handlers.set(NotifType.PAYMENT_CANCELLATION, this.paymentCancellationHandler);
|
||||
|
||||
this.handlers.set(NotifType.USER_PASSWORD, this.userPasswordHandler);
|
||||
|
||||
this.logger.log(`Registered ${this.handlers.size} notification handlers`);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { Injectable, Logger } from "@nestjs/common";
|
||||
import { QueryRunner } from "typeorm";
|
||||
|
||||
import { BaseNotificationHandler } from "./base-notification.handler";
|
||||
import { IUserPasswordNotificationData } from "../interfaces/ISendNotificationData";
|
||||
import { NotificationsService } from "../providers/notifications.service";
|
||||
|
||||
@Injectable()
|
||||
export class UserPasswordHandler extends BaseNotificationHandler<IUserPasswordNotificationData> {
|
||||
protected readonly logger = new Logger(UserPasswordHandler.name);
|
||||
|
||||
constructor(private readonly notificationsService: NotificationsService) {
|
||||
super();
|
||||
}
|
||||
|
||||
protected async handle(recipientId: string, data: IUserPasswordNotificationData, queryRunner: QueryRunner): Promise<void> {
|
||||
await this.notificationsService.createUserPasswordNotification(recipientId, data, queryRunner);
|
||||
}
|
||||
|
||||
protected getHandlerName(): string {
|
||||
return "UserPassword";
|
||||
}
|
||||
}
|
||||
@@ -82,3 +82,7 @@ export interface INewCriticismNotificationData extends IBaseNotificationData {
|
||||
title: string;
|
||||
fullName: string;
|
||||
}
|
||||
|
||||
export interface IUserPasswordNotificationData extends IBaseNotificationData {
|
||||
password: string;
|
||||
}
|
||||
|
||||
@@ -5,34 +5,28 @@ import { TypeOrmModule } from "@nestjs/typeorm";
|
||||
|
||||
import { NOTIFICATION } from "./constants";
|
||||
import { Notification } from "./entities/notification.entity";
|
||||
import { BlogCommentHandler } from "./handlers/blog-comment.handler";
|
||||
import { NotificationController } from "./notifications.controller";
|
||||
import { LoggerModule } from "../logger/logger.module";
|
||||
import {
|
||||
AnnouncementHandler,
|
||||
AnswerTicketHandler,
|
||||
ApproveInvoiceHandler,
|
||||
AssignTicketHandler,
|
||||
BillInvoiceHandler,
|
||||
BillInvoiceReminderHandler,
|
||||
BlockServiceHandler,
|
||||
BlogCommentHandler,
|
||||
CreateInvoiceHandler,
|
||||
CreateTicketHandler,
|
||||
InvoiceOverdueHandler,
|
||||
NewCriticismHandler,
|
||||
NewCustomerHandler,
|
||||
NewSubscriptionHandler,
|
||||
NewTicketHandler,
|
||||
NotificationHandlerFactory,
|
||||
OtpHandler,
|
||||
PaymentCancellationHandler,
|
||||
PaymentReminderHandler,
|
||||
RecurringInvoiceHandler,
|
||||
ServiceReviewHandler,
|
||||
UserLoginHandler,
|
||||
WalletChargeHandler,
|
||||
WalletDeductionHandler,
|
||||
} from "./handlers";
|
||||
import { NotificationController } from "./notifications.controller";
|
||||
import { LoggerModule } from "../logger/logger.module";
|
||||
} from "./handlers/admin-notifications.handler";
|
||||
import { AnnouncementHandler } from "./handlers/announcement.handler";
|
||||
import {
|
||||
ApproveInvoiceHandler,
|
||||
BillInvoiceHandler,
|
||||
BillInvoiceReminderHandler,
|
||||
CreateInvoiceHandler,
|
||||
InvoiceOverdueHandler,
|
||||
RecurringInvoiceHandler,
|
||||
} from "./handlers/invoice.handler";
|
||||
import { PaymentCancellationHandler, PaymentReminderHandler } from "./handlers/payment.handler";
|
||||
import { BlockServiceHandler } from "./handlers/service.handler";
|
||||
import { AnswerTicketHandler, AssignTicketHandler, CreateTicketHandler, NewTicketHandler } from "./handlers/ticket.handler";
|
||||
import { UserPasswordHandler } from "./handlers/user-password.handler";
|
||||
import { NotificationsService } from "./providers/notifications.service";
|
||||
import { NotificationProcessor } from "./queue/notification.processor";
|
||||
import { NotificationQueue } from "./queue/notification.queue";
|
||||
@@ -40,6 +34,10 @@ import { NotificationRepository } from "./repositories/notifications.repository"
|
||||
import { NotificationSetting } from "../settings/entities/notification-setting.entity";
|
||||
import { SettingModule } from "../settings/settings.module";
|
||||
import { UtilsModule } from "../utils/utils.module";
|
||||
import { NotificationHandlerFactory } from "./handlers/notification-handler.factory";
|
||||
import { OtpHandler } from "./handlers/otp.handler";
|
||||
import { UserLoginHandler } from "./handlers/user-login.handler";
|
||||
import { WalletChargeHandler, WalletDeductionHandler } from "./handlers/wallet.handler";
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -92,6 +90,7 @@ import { UtilsModule } from "../utils/utils.module";
|
||||
BlockServiceHandler,
|
||||
PaymentReminderHandler,
|
||||
PaymentCancellationHandler,
|
||||
UserPasswordHandler,
|
||||
],
|
||||
controllers: [NotificationController],
|
||||
exports: [NotificationRepository, NotificationsService, NotificationQueue],
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
IServiceReviewNotificationData,
|
||||
ISubscriptionNotificationData,
|
||||
ITicketNotificationData,
|
||||
IUserPasswordNotificationData,
|
||||
IWalletNotificationData,
|
||||
} from "../interfaces/ISendNotificationData";
|
||||
import { NotificationRepository } from "../repositories/notifications.repository";
|
||||
@@ -551,4 +552,15 @@ export class NotificationsService {
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
//************************************************* */
|
||||
|
||||
async createUserPasswordNotification(recipientId: string, data: IUserPasswordNotificationData, queryRunner: QueryRunner) {
|
||||
const message = NotificationMessage.USER_PASSWORD_MESSAGE.replace("[password]", data.password);
|
||||
|
||||
await this.smsService.sendUserPasswordSms(data.userPhone, data.password);
|
||||
return this.createNotification(
|
||||
{ title: NotificationMessage.USER_PASSWORD, type: NotifType.USER_PASSWORD, message, recipientId },
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
IServiceReviewNotificationData,
|
||||
ISubscriptionNotificationData,
|
||||
ITicketNotificationData,
|
||||
IUserPasswordNotificationData,
|
||||
IWalletNotificationData,
|
||||
} from "../interfaces/ISendNotificationData";
|
||||
|
||||
@@ -145,4 +146,8 @@ export class NotificationQueue {
|
||||
async addPaymentCancellationNotification(recipientId: string, data: IPaymentNotificationData) {
|
||||
await this.addNotificationJob(NotifType.PAYMENT_CANCELLATION, recipientId, data);
|
||||
}
|
||||
|
||||
async addUserPasswordNotification(recipientId: string, data: IUserPasswordNotificationData) {
|
||||
await this.addNotificationJob(NotifType.USER_PASSWORD, recipientId, data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user