add api notify-from-token
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m5s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m5s
This commit is contained in:
parent
af2bd5054f
commit
cab2f76bd6
1 changed files with 24 additions and 1 deletions
|
|
@ -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 || [],
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue