add api notify-from-token
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m5s

This commit is contained in:
Warunee Tamkoo 2026-05-14 12:33:21 +07:00
parent af2bd5054f
commit cab2f76bd6

View file

@ -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 { sendWebSocket } from "../services/webSocket";
import { RequestWithUser } from "../middlewares/user";
@Route("/api/v1/org/through-socket") @Route("/api/v1/org/through-socket")
export class SocketController extends Controller { 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 || [],
},
);
}
} }