fix: add notif type to create notification

This commit is contained in:
mahyargdz
2025-03-02 16:52:31 +03:30
parent 28486d64ee
commit c559fdb9e8
4 changed files with 19 additions and 16 deletions
@@ -1,6 +1,7 @@
import { IsNotEmpty, IsString, IsUUID } from "class-validator";
import { IsEnum, IsNotEmpty, IsString, IsUUID } from "class-validator";
import { NotificationMessage } from "../../../common/enums/message.enum";
import { NotifType } from "../../settings/enums/notif-settings.enum";
export class CreateNotificationDto {
@IsNotEmpty({ message: NotificationMessage.TITLE_IS_REQUIRED })
@@ -15,4 +16,8 @@ export class CreateNotificationDto {
@IsString({ message: NotificationMessage.USERID_IS_STRING })
@IsUUID("4", { message: NotificationMessage.USERID_IS_UUID })
recipientId: string;
@IsNotEmpty()
@IsEnum(NotifType)
type: NotifType;
}
@@ -1,8 +1,8 @@
import { Column, Entity, ManyToOne } from "typeorm";
import { BaseEntity } from "../../../common/entities/base.entity";
import { NotifType } from "../../settings/enums/notif-settings.enum";
import { User } from "../../users/entities/user.entity";
import { NotificationType } from "../enums/notification-type.enum";
@Entity()
export class Notification extends BaseEntity {
@@ -12,8 +12,8 @@ export class Notification extends BaseEntity {
@Column({ type: "text", nullable: false })
message: string;
@Column({ type: "enum", enum: NotificationType, default: NotificationType.LOGIN })
type: NotificationType;
@Column({ type: "enum", enum: NotifType, nullable: false })
type: NotifType;
@Column({ type: "boolean", default: false })
isRead: boolean;
@@ -1,5 +0,0 @@
export enum NotificationType {
LOGIN = "LOGIN",
PASSWORD_CHANGED = "PASSWORD_CHANGED",
WALLET_CHARGED = "WALLER_CHARGED",
}
@@ -124,7 +124,7 @@ export class NotificationsService {
await this.smsService.sendLoginSms(sendNotifData.userPhone, loginDate);
//send email too
}
return this.createNotification({ title: NotificationMessage.LOGIN, message, recipientId });
return this.createNotification({ title: NotificationMessage.LOGIN, type: NotifType.USER_LOGIN, message, recipientId });
}
//************************ */
@@ -147,7 +147,10 @@ export class NotificationsService {
);
//send email too
}
return this.createNotification({ title: NotificationMessage.INVOICE_CREATION, message, recipientId }, queryRunner);
return this.createNotification(
{ title: NotificationMessage.INVOICE_CREATION, type: NotifType.CREATE_INVOICE, message, recipientId },
queryRunner,
);
}
//************************ */
@@ -163,7 +166,7 @@ export class NotificationsService {
await this.smsService.sendAnnouncementSms(data.userPhone, data.title, data.description, dateFormat(data.date));
//send email too
}
return this.createNotification({ title: NotificationMessage.ANNOUNCEMENT, message, recipientId });
return this.createNotification({ title: NotificationMessage.ANNOUNCEMENT, type: NotifType.ANNOUNCEMENT, message, recipientId });
}
//************************ */
@@ -185,7 +188,7 @@ export class NotificationsService {
);
//send email too
}
return this.createNotification({ title: NotificationMessage.WALLET_CHARGE, message, recipientId });
return this.createNotification({ title: NotificationMessage.WALLET_CHARGE, type: NotifType.WALLET_CHARGE, message, recipientId });
}
//************************ */
@@ -208,7 +211,7 @@ export class NotificationsService {
);
//send email too
}
return this.createNotification({ title: NotificationMessage.WALLET_DEDUCTION, message, recipientId });
return this.createNotification({ title: NotificationMessage.WALLET_DEDUCTION, type: NotifType.WALLET_DEDUCTION, message, recipientId });
}
// //************************ */
@@ -225,7 +228,7 @@ export class NotificationsService {
await this.smsService.sendAnswerTicketSms(data.userPhone, data.ticketId, data.subject);
//send email too
}
return this.createNotification({ title: NotificationMessage.ANSWER_TICKET, message, recipientId });
return this.createNotification({ title: NotificationMessage.ANSWER_TICKET, type: NotifType.ANSWER_TICKET, message, recipientId });
}
// //************************ */
@@ -242,7 +245,7 @@ export class NotificationsService {
await this.smsService.sendCreateTicketSms(data.userPhone, data.ticketId, data.subject, dateFormat(data.date));
//send email too
}
return this.createNotification({ title: NotificationMessage.CREATE_TICKET, message, recipientId });
return this.createNotification({ title: NotificationMessage.CREATE_TICKET, type: NotifType.CREATE_TICKET, message, recipientId });
}
//************************ */