feat: implement comprehensive notification engine with policies, preferences, and automated dispatching services

This commit is contained in:
2026-07-21 18:53:11 -03:00
parent 40090cdec5
commit 10ca449f88
82 changed files with 10249 additions and 171 deletions
@@ -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,