MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / post

Method post

apps/web/server/routers/messages/controller.ts:69–103  ·  view source on GitHub ↗
(
    req: AuthedRequestWithTenantAndBody<postMessageType>,
    res: Response,
    next: NextFunction
  )

Source from the content-addressed store, hash-verified

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>,

Callers 1

index.tsFile · 0.45

Calls 5

isNotManagerFunction · 0.90
trackApiEventFunction · 0.90
toFunction · 0.85
isChannelUsableMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected