⚙️ Organization handlers
Organization 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. These exports are terminators that shape HTTP responses after prior pipeline steps.
Inventory
| Handler | Pipeline role | Inputs / context | Result / behavior / errors | Used by routes |
|---|---|---|---|---|
normalizeOrganizationTerminator | Terminator | context.data.organization | Removes _id and returns the organization; missing organization is 500. | createOrganizationRoute, getOrganizationRoute, updateOrganizationRoute, updateOrganizationAsAdminRoute |
normalizeOrganizationsListTerminator | Terminator | context.data.organizations | Removes _id from an array or paginated data; malformed or missing value is 500. | findOrganizationsRoute |
deleteOrganizationTerminator | Terminator | context.data.hasDeletedOrganization | Returns {statusCode: 204} when deletion succeeded; otherwise 500. | deleteOrganizationRoute |
normalizeOrganizationMemberExistenceTerminator | Terminator | context.data.isMemberOfOrganization | Returns {isMemberOfOrganization}; missing value is 500. | checkOrganizationMemberExistenceRoute |
normalizeOrganizationMembersListTerminator | Terminator | context.data.organizationMembers | Returns the member array or paginated shape; malformed or missing value is 500. | findOrganizationMembersRoute |
deleteOrganizationMemberTerminator | Terminator | context.data.hasDeletedOrganizationMember | Returns {statusCode: 204} when member deletion succeeded; otherwise 500. | deleteOrganizationMemberRoute |
upsertOrganizationMembersTerminator | Terminator | context.data.hasUpsertedOrganizationMembers | Returns {statusCode: 204} when upsert succeeded; otherwise 500. | upsertOrganizationMembersRoute |
Details
normalizeOrganizationTerminator
Implementation
Throws result.error when the pipeline result is an error. On success, reads context.data.organization, removes its database-only _id, and returns the remaining public organization object. Missing organization throws NodeblocksError(500, 'Unknown error normalizing organization', 'normalizeOrganizationTerminator'). Used by createOrganizationRoute, getOrganizationRoute, updateOrganizationRoute, and updateOrganizationAsAdminRoute.
normalizeOrganizationsListTerminator
Implementation
Throws result.error when the pipeline result is an error. Reads context.data.organizations: for an array, removes _id from each item; for a paginated value, returns {data, metadata: {pagination}} with _id removed from each item. A value that is neither an array nor an object with array data throws NodeblocksError(500, 'Unknown error normalizing organizations list', 'normalizeOrganizationsListTerminator'). Used by findOrganizationsRoute.
deleteOrganizationTerminator
Implementation
Throws result.error when the pipeline result is an error. Requires truthy context.data.hasDeletedOrganization, then returns {statusCode: 204}. A missing or false value throws NodeblocksError(500, 'Unknown error deleting organization', 'deleteOrganizationTerminator'). Used by deleteOrganizationRoute, where it is the final terminator.
normalizeOrganizationMemberExistenceTerminator
Implementation
Throws result.error when the pipeline result is an error. Reads context.data.isMemberOfOrganization and returns {isMemberOfOrganization}; false is valid, but a null or undefined value throws NodeblocksError(500, 'Unknown error normalizing organization member existence', 'normalizeOrganizationMemberExistenceTerminator'). Used by checkOrganizationMemberExistenceRoute.
normalizeOrganizationMembersListTerminator
Implementation
Throws result.error when the pipeline result is an error. Reads context.data.organizationMembers and returns it directly when it is an array; for a paginated value, returns {data, metadata: {pagination}}. A value that is neither form throws NodeblocksError(500, 'Unknown error normalizing organization members', 'normalizeOrganizationMembersListTerminator'). Used by findOrganizationMembersRoute.
deleteOrganizationMemberTerminator
Implementation
Throws result.error when the pipeline result is an error. Requires truthy context.data.hasDeletedOrganizationMember, then returns {statusCode: 204}. A missing or false value throws NodeblocksError(500, 'Unknown error deleting organization member', 'deleteOrganizationMemberTerminator'). Used by deleteOrganizationMemberRoute, where it is the final terminator.
upsertOrganizationMembersTerminator
Implementation
Throws result.error when the pipeline result is an error. Requires truthy context.data.hasUpsertedOrganizationMembers, then returns {statusCode: 204}. A missing or false value throws NodeblocksError(500, 'Unknown error when trying to upsert organization members', 'upsertOrganizationMembersTerminator'). Used by upsertOrganizationMembersRoute, where it is the final terminator.