feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services
This commit is contained in:
@@ -63,6 +63,11 @@ export type CreateSystemNotificationParams = {
|
||||
code?: string;
|
||||
};
|
||||
|
||||
export type CreateSystemNotificationBySystemParams = CreateSystemNotificationParams & {
|
||||
userId: string;
|
||||
systemToken: string;
|
||||
};
|
||||
|
||||
export type UpdateSystemNotificationParams = {
|
||||
id: string;
|
||||
readed: boolean;
|
||||
@@ -119,6 +124,7 @@ export interface ISystemNotificationsAdapter {
|
||||
export interface ISystemNotificationsManager {
|
||||
notifications: ISystemNotificationsAdapter;
|
||||
createNotification(data: CreateSystemNotificationParams): Promise<ISystemNotification>;
|
||||
createNotificationBySystem(data: CreateSystemNotificationBySystemParams): Promise<ISystemNotification>;
|
||||
updateNotification(data: UpdateSystemNotificationParams): Promise<void>;
|
||||
deleteNotification(data: DeleteSystemNotificationParams): Promise<void>;
|
||||
deleteConversationNotifications(data: DeleteSystemNotificationsByConversation): Promise<void>;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import CompaniesManager from "../Companies/Companies";
|
||||
import {
|
||||
CreateSystemNotificationParams,
|
||||
CreateSystemNotificationBySystemParams,
|
||||
DeleteNotificationsByDateParams,
|
||||
DeleteNotificationsByUserParams,
|
||||
DeleteSystemNotificationParams,
|
||||
@@ -108,6 +109,28 @@ class SystemNotificationsManager implements ISystemNotificationsManager {
|
||||
return newNotification;
|
||||
}
|
||||
|
||||
public async createNotificationBySystem(
|
||||
data: CreateSystemNotificationBySystemParams
|
||||
): Promise<ISystemNotification> {
|
||||
const expectedToken = process.env.SYSTEM_KEY || process.env.API_KEY;
|
||||
|
||||
if (!expectedToken || data.systemToken !== expectedToken) {
|
||||
throw new Error("Token de sistema inválido");
|
||||
}
|
||||
|
||||
const { systemToken, ...notificationData } = data;
|
||||
const notification = await this.createNotification(notificationData);
|
||||
|
||||
const countUnreadNotifications = await this.finUnreadNotifications({
|
||||
userId: data.userId,
|
||||
sessionUser: data.userId,
|
||||
});
|
||||
|
||||
io.to(`user:${data.userId}`).emit("new_system_notification", countUnreadNotifications);
|
||||
|
||||
return notification;
|
||||
}
|
||||
|
||||
public async updateNotification(data: UpdateSystemNotificationParams): Promise<void> {
|
||||
await validateSessionUser({
|
||||
sessionUser: data.sessionUser,
|
||||
|
||||
Reference in New Issue
Block a user