feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services
This commit is contained in:
@@ -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