hrms-api-org/src/controllers/SocketController.ts

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-05-14 12:33:21 +07:00
import { Body, Controller, Post, Request, Route, Security } from "tsoa";
import { sendWebSocket } from "../services/webSocket";
2026-05-14 12:33:21 +07:00
import { RequestWithUser } from "../middlewares/user";
2025-09-02 16:18:48 +07:00
@Route("/api/v1/org/through-socket")
export class SocketController extends Controller {
@Post("notify")
async notify(
@Body()
payload: {
message: string;
userId?: string | string[];
roles?: string | string[];
error?: boolean;
},
) {
sendWebSocket(
"socket-notification",
{ success: !payload.error, message: payload.message },
{
roles: payload.roles || [],
userId: payload.userId || [],
},
);
}
2026-05-14 12:33:21 +07:00
@Post("notify-from-token")
@Security("bearerAuth")
async notifyFromToken(
@Body()
payload: {
message: string;
targetUserId?: string | string[];
roles?: string | string[];
error?: boolean;
},
@Request() req: RequestWithUser,
) {
sendWebSocket(
"socket-notification",
{ success: !payload.error, message: payload.message },
{
roles: payload.roles || req.user.role || [],
userId: payload.targetUserId || req.user.sub || [],
},
);
}
}