fixed web socket noti by token
This commit is contained in:
parent
74d03176cd
commit
e3777c6731
1 changed files with 17 additions and 4 deletions
|
|
@ -36,13 +36,26 @@ export class SocketController extends Controller {
|
||||||
},
|
},
|
||||||
@Request() req: RequestWithUser,
|
@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(
|
sendWebSocket(
|
||||||
"socket-notification",
|
"socket-notification",
|
||||||
{ success: !payload.error, message: payload.message },
|
{ success: !payload.error, message: payload.message },
|
||||||
{
|
recipients,
|
||||||
roles: payload.roles || req.user.role || [],
|
|
||||||
userId: payload.targetUserId || req.user.sub || [],
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue