Abhises commited on
Commit
a793f2f
·
1 Parent(s): 80917de

added notificaion detail

Browse files
Files changed (2) hide show
  1. src/controllers/admin.js +1 -1
  2. src/lib/ws.js +14 -1
src/controllers/admin.js CHANGED
@@ -29,7 +29,7 @@ const sendNotification = async (req, res) => {
29
  });
30
 
31
  const wsManager = require('../lib/ws');
32
- wsManager.broadcastGlobalNotification({
33
  type: 'admin_broadcast',
34
  id: notification.id,
35
  title,
 
29
  });
30
 
31
  const wsManager = require('../lib/ws');
32
+ await wsManager.broadcastGlobalNotification({
33
  type: 'admin_broadcast',
34
  id: notification.id,
35
  title,
src/lib/ws.js CHANGED
@@ -75,10 +75,23 @@ class SocketManager {
75
  }
76
  }
77
 
78
- broadcastGlobalNotification(payload) {
79
  if (this.io) {
80
  this.io.emit('notification', payload);
81
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  }
83
  }
84
 
 
75
  }
76
  }
77
 
78
+ async broadcastGlobalNotification(payload) {
79
  if (this.io) {
80
  this.io.emit('notification', payload);
81
  }
82
+ try {
83
+ const workspaces = await prisma.workspace.findMany({ select: { id: true } });
84
+ if (workspaces.length > 0) {
85
+ const notifications = workspaces.map(ws => ({
86
+ workspaceId: ws.id,
87
+ type: payload.type,
88
+ payload: JSON.stringify(payload),
89
+ }));
90
+ await prisma.notification.createMany({ data: notifications });
91
+ }
92
+ } catch (err) {
93
+ console.error('Failed to persist global notifications:', err);
94
+ }
95
  }
96
  }
97