diff --git a/src/controllers/SocketController.ts b/src/controllers/SocketController.ts index eb0b72c2..c975336f 100644 --- a/src/controllers/SocketController.ts +++ b/src/controllers/SocketController.ts @@ -1,5 +1,6 @@ -import { Body, Controller, Post, Route } from "tsoa"; +import { Body, Controller, Post, Request, Route, Security } from "tsoa"; import { sendWebSocket } from "../services/webSocket"; +import { RequestWithUser } from "../middlewares/user"; @Route("/api/v1/org/through-socket") export class SocketController extends Controller { @@ -22,4 +23,26 @@ export class SocketController extends Controller { }, ); } + + @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 || [], + }, + ); + } }