メインコンテンツまでスキップ
バージョン: 🚧 Canary

⚙️ Chat handlers

Chat handlers are route-pipeline functions, not Express middleware. They read RouteHandlerPayload values from params and context, merge successful values into context.data, or terminate a successful Result with an HTTP response descriptor.

Inventory

HandlerPipeline roleInputs / contextResult / behavior / errorsUsed by routes
createChatChannelHandlerrequestBody, db.chatChannelsCreates a base entity and writes channelId and channel; 400 for an empty body or failed insert, 500 on database failure.createChatChannelRoute
getChatChannelByIdHandlercontext.data.channelId or path channelId, db.chatChannelsWrites channel; 400 without an ID, 404 when absent, 500 on database failure.createChatChannelRoute, getChatChannelRoute, updateChatChannelRoute
findChatChannelsHandlerrequestQuery, db.chatChannelsWrites channels from query filter (defaults to {}); 500 on database failure.findChatChannelsRoute
updateChatChannelHandlerPath/context channel ID, requestBody, optional fileStorageDriverUpdates the channel, removes a replaced icon from storage, and writes channelId; 400, 404, or 500 on invalid or failed work.updateChatChannelRoute
deleteChatChannelHandlerPath/context channel ID, db.chatChannels, optional fileStorageDriverDeletes the channel and existing icon, then writes deleteChatChannel: true; 400, 404, or 500 on failure.deleteChatChannelRoute
createChatChannelTerminatorTerminatorcontext.data.channel, optional fileStorageDriverNormalizes the created channel and returns { data, statusCode: 201 }; missing data or normalization failure becomes an error.createChatChannelRoute
normalizeChatChannelTerminatorTerminatorcontext.data.channel, optional fileStorageDriverReturns the normalized channel; missing channel data produces 500.getChatChannelRoute, updateChatChannelRoute
normalizeChatChannelsListTerminatorTerminatorRaw or paginated context.data.channels, optional fileStorageDriverNormalizes every channel while retaining pagination metadata; invalid pipeline data produces 500.findChatChannelsRoute
deleteChatChannelTerminatorTerminatorcontext.data.deleteChatChannelReturns { statusCode: 204 }; missing success state produces 500.deleteChatChannelRoute
getChatMessageByIdHandlercontext.data.messageId or path messageId, db.chatMessagesWrites chatMessage; 400 without an ID, 404 when absent, 500 on database failure.getChatMessageRoute, updateChatMessageRoute
findChatMessagesHandlerrequestQuery, db.chatMessagesSorts by createdAt descending and writes chatMessages; 500 on database failure.Custom composition only
updateChatMessageHandlerPath/context message ID, requestBody, db.chatMessagesUpdates the entity and writes messageId; 400, 404, or 500 on failure.updateChatMessageRoute
deleteChatMessageHandlerPath/context message ID, db.chatMessagesDeletes the entity and writes deleteChatMessage: true; 400, 404, or 500 on failure.deleteChatMessageRoute
createChatMessageTerminatorTerminatorcontext.data.chatMessageRemoves _id and returns { data, statusCode: 201 }; missing data produces 500.Custom composition only
normalizeChatMessageTerminatorTerminatorcontext.data.chatMessageRemoves _id and returns the message; missing data produces 500.Custom composition only
normalizeChatMessagesListTerminatorTerminatorRaw or paginated context.data.chatMessagesRemoves _id from each message and retains pagination metadata; invalid data produces 500.Custom composition only
deleteChatMessageTerminatorTerminatorcontext.data.deleteChatMessageReturns { statusCode: 204 }; missing success state produces 500.deleteChatMessageRoute
createChatSubscriptionHandlerrequestBody, db.subscriptionsCreates a base entity and writes subscriptionId and subscription; 400 or 500 on failure.createChatSubscriptionRoute
getChatSubscriptionByIdHandlercontext.data.subscriptionId or path subscriptionId, db.subscriptionsWrites subscription; 400 without an ID, 404 when absent, 500 on database failure.createChatSubscriptionRoute, getChatSubscriptionRoute
findChatSubscriptionsHandlerrequestQuery, db.subscriptionsWrites subscriptions from query filter (defaults to {}); 500 on database failure.findChatSubscriptionsRoute
deleteChatSubscriptionHandlerPath/context subscription ID, db.subscriptionsDeletes the entity and writes deleteChatSubscription: true; 400, 404, or 500 on failure.deleteChatSubscriptionRoute
createChatSubscriptionTerminatorTerminatorcontext.data.subscriptionRemoves _id and returns { data, statusCode: 201 }; missing data produces 500.createChatSubscriptionRoute
normalizeChatSubscriptionTerminatorTerminatorcontext.data.subscriptionRemoves _id and returns the subscription; missing data produces 500.getChatSubscriptionRoute
normalizeChatSubscriptionsListTerminatorTerminatorRaw or paginated context.data.subscriptionsRemoves _id and retains pagination metadata; invalid data produces 500.findChatSubscriptionsRoute
deleteChatSubscriptionTerminatorTerminatorcontext.data.deleteChatSubscriptionReturns { statusCode: 204 }; missing success state produces 500.deleteChatSubscriptionRoute

Details

createChatChannel

Implementation

Reads params.requestBody, rejects an absent or empty body with 400, creates a base entity in context.db.chatChannels, and merges both channelId and the created channel into pipeline data. A missing insertedId is 400; thrown database errors become 500. Used by createChatChannelRoute.

getChatChannelById

Implementation

Reads the channel ID from context.data.channelId first and then params.requestParams.channelId, fetches from context.db.chatChannels, and merges the document as channel. Missing IDs return 400, absent channels return 404, and database failures return 500. Used by createChatChannelRoute, getChatChannelRoute, and updateChatChannelRoute.

findChatChannels

Implementation

Uses params.requestQuery || {} directly as the MongoDB filter and merges the resulting array as channels; query failures return 500. findChatChannelsRoute wraps it with pagination before normalization.

updateChatChannel

Implementation

Reads the channel ID from prior data or the path and requires a non-empty body. It loads the previous channel, applies updateBaseEntity, removes a replaced icon through fileStorageDriver when present, and merges channelId for the following lookup. It returns 400 for missing inputs, 404 when the channel is absent, and 500 for database or file deletion failures. Used by updateChatChannelRoute.

deleteChatChannel

Implementation

Reads the channel ID from prior data or the path, loads and deletes the channel, deletes its icon through fileStorageDriver when applicable, and writes deleteChatChannel: true. Missing IDs return 400, a missing channel returns 404, and database or storage failures return 500. Used by deleteChatChannelRoute.

createChatChannelTerminator

Implementation

Requires context.data.channel, normalizes its optional icon with fileStorageDriver, and returns { data: normalizedChannel, statusCode: 201 }. It throws prior errors unchanged and reports 500 if pipeline data is missing or normalization fails. Final step of createChatChannelRoute.

normalizeChatChannelTerminator

Implementation

Requires context.data.channel, normalizes its optional icon with fileStorageDriver, and returns the normalized entity as the ordinary response body. It throws prior errors and emits 500 for missing pipeline data. Used by getChatChannelRoute and updateChatChannelRoute.

normalizeChatChannelsListTerminator

Implementation

Accepts either a raw channel array or the paginated { data, ...metadata } shape, normalizes each icon, and returns the same outer shape with normalized data. Invalid pipeline data produces 500; normalization errors are propagated. Used by findChatChannelsRoute.

deleteChatChannelTerminator

Implementation

Requires context.data.deleteChatChannel and returns { statusCode: 204 }, producing an empty successful response. Missing success state produces 500. Final step of deleteChatChannelRoute.

getChatMessageById

Implementation

Reads the message ID from context.data.messageId first and then the path, fetches from context.db.chatMessages, and merges the document as chatMessage. Missing IDs return 400, absent messages return 404, and database failures return 500. Used by getChatMessageRoute and updateChatMessageRoute.

findChatMessages

Implementation

Uses params.requestQuery as a MongoDB filter, sorts results by createdAt descending, and merges them as chatMessages; database failures return 500. No exported Chat route uses this handler—the current list and read-state routes call the similarly named block export.

updateChatMessage

Implementation

Reads the message ID from prior data or the path, requires a non-empty request body, updates with updateBaseEntity, and merges messageId. It returns 400 for missing inputs, 404 when no message matches, and 500 for database failures. Used by updateChatMessageRoute.

deleteChatMessage

Implementation

Reads the message ID from prior data or the path, deletes it from context.db.chatMessages, and writes deleteChatMessage: true. It returns 400 without an ID, 404 when nothing is deleted, and 500 on database failure. Used by deleteChatMessageRoute.

createChatMessageTerminator

Implementation

Requires context.data.chatMessage, removes MongoDB _id, and returns { data: chatMessage, statusCode: 201 }; missing data produces 500. This legacy terminator is public but is not used by an exported Chat route.

normalizeChatMessageTerminator

Implementation

Requires context.data.chatMessage, removes MongoDB _id, and returns the remaining entity; missing data produces 500. This public legacy terminator is available only for custom composition.

normalizeChatMessagesListTerminator

Implementation

Accepts a raw or paginated context.data.chatMessages collection, removes _id from every message, and preserves pagination metadata. Invalid pipeline data produces 500. No exported Chat route currently uses it.

deleteChatMessageTerminator

Implementation

Requires context.data.deleteChatMessage and returns { statusCode: 204 }; missing success state produces 500. Final step of deleteChatMessageRoute.

createChatSubscription

Implementation

Requires a non-empty body, creates a base entity in context.db.subscriptions, and merges subscriptionId and subscription. A missing body or failed insertion returns 400; database failures return 500. Used by createChatSubscriptionRoute.

getChatSubscriptionById

Implementation

Reads the subscription ID from prior data or the path, fetches from context.db.subscriptions, and merges subscription. Missing IDs return 400, absent subscriptions return 404, and database failures return 500. Used by createChatSubscriptionRoute and getChatSubscriptionRoute.

findChatSubscriptions

Implementation

Uses params.requestQuery || {} as the MongoDB filter and merges the resulting array as subscriptions; database failures return 500. findChatSubscriptionsRoute wraps it with pagination.

deleteChatSubscription

Implementation

Reads the subscription ID from prior data or the path, deletes it, and writes deleteChatSubscription: true. Missing IDs return 400, absent subscriptions return 404, and database failures return 500. Used by deleteChatSubscriptionRoute.

createChatSubscriptionTerminator

Implementation

Requires context.data.subscription, removes MongoDB _id, and returns { data: subscription, statusCode: 201 }; missing data produces 500. Final step of createChatSubscriptionRoute.

normalizeChatSubscriptionTerminator

Implementation

Requires context.data.subscription, removes MongoDB _id, and returns the entity; missing data produces 500. Final step of getChatSubscriptionRoute.

normalizeChatSubscriptionsListTerminator

Implementation

Accepts a raw or paginated subscription collection, removes _id from each item, and preserves pagination metadata. Invalid pipeline data produces 500. Final step of findChatSubscriptionsRoute.

deleteChatSubscriptionTerminator

Implementation

Requires context.data.deleteChatSubscription and returns { statusCode: 204 }; missing success state produces 500. Final step of deleteChatSubscriptionRoute.