fixed web socket noti by token
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m1s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m1s
This commit is contained in:
parent
74d03176cd
commit
b103e15788
1 changed files with 17 additions and 4 deletions
|
|
@ -36,13 +36,26 @@ export class SocketController extends Controller {
|
|||
},
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
const toArray = (value?: string | string[]) => {
|
||||
if (Array.isArray(value)) return value.filter(Boolean);
|
||||
if (typeof value === "string" && value.trim()) return [value];
|
||||
return [] as string[];
|
||||
};
|
||||
|
||||
const targetUserIds = toArray(payload.targetUserId);
|
||||
const targetRoles = toArray(payload.roles);
|
||||
|
||||
// If caller provides explicit user targets, do not combine with role targeting.
|
||||
// This prevents accidental broad notifications when roles include common roles.
|
||||
const recipients =
|
||||
targetUserIds.length > 0
|
||||
? { userId: targetUserIds, roles: [] as string[] }
|
||||
: { userId: [req.user.sub], roles: targetRoles };
|
||||
|
||||
sendWebSocket(
|
||||
"socket-notification",
|
||||
{ success: !payload.error, message: payload.message },
|
||||
{
|
||||
roles: payload.roles || req.user.role || [],
|
||||
userId: payload.targetUserId || req.user.sub || [],
|
||||
},
|
||||
recipients,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue