(
req: AuthedRequestWithTenantAndBody<postMessageType>,
res: Response,
next: NextFunction
)
| 67 | } |
| 68 | |
| 69 | static async post( |
| 70 | req: AuthedRequestWithTenantAndBody<postMessageType>, |
| 71 | res: Response, |
| 72 | next: NextFunction |
| 73 | ) { |
| 74 | if (req.tenant?.chat === ChatType.NONE) { |
| 75 | return next(new Forbidden('Community has chat disabled')); |
| 76 | } |
| 77 | |
| 78 | if ( |
| 79 | req.tenant?.chat === ChatType.MANAGERS && |
| 80 | isNotManager(req.tenant_user?.role) |
| 81 | ) { |
| 82 | return next(new Forbidden('User is not allow to chat')); |
| 83 | } |
| 84 | |
| 85 | const [err, _] = await to( |
| 86 | ChannelsService.isChannelUsable({ |
| 87 | channelId: req.body.channelId, |
| 88 | accountId: req.tenant?.id!, |
| 89 | }) |
| 90 | ); |
| 91 | if (err) { |
| 92 | return next(new BadRequest(err.message)); |
| 93 | } |
| 94 | |
| 95 | const message = await MessagesService.create({ |
| 96 | ...req.body, |
| 97 | userId: req.tenant_user?.id!, |
| 98 | }); |
| 99 | |
| 100 | await trackApiEvent({ req, res }, ApiEvent.user_send_message); |
| 101 | |
| 102 | res.json(message); |
| 103 | } |
| 104 | |
| 105 | static async put( |
| 106 | req: AuthedRequestWithTenantAndBody<putMessageType>, |
no test coverage detected