🛣️ Order routes
Order routes are SDK composers, not Express middleware. Compose them through the matching features, then mount the service as shown in the Order integration guide.
Inventory
Details
createOrderRoute
Implementation
Endpoint: POST /orders
Creates an order for the supplied identityId, then reads it back before responding.
Access: Authenticated administrator, or an authenticated identity whose ID equals requestBody.identityId.
Request: createOrderSchema requires an application/json body with identityId, items, and total.
Pipeline: createOrder → getOrderById → createOrderTerminator.
Success: 201 with the created order object. The terminator removes MongoDB _id.
Failure: The handlers can report missing request data (400), creation failure (400), a missing reread order (404), or database errors (500). Authentication and authorization failures originate in the shared and local validators.View complete source
getOrderRoute
Implementation
Endpoint: GET /orders/:orderId
Gets one order and normalizes its public response.
Access: Authenticated administrator, or an authenticated identity that owns the order.
Request: getOrderSchema requires path parameter orderId.
Pipeline: getOrderById → normalizeOrderTerminator.
Success: Default Express JSON behavior produces 200 with the order object; the terminator removes _id.
Failure: getOrderById returns 400 without an ID, 404 when the order is absent, and 500 for a database failure. The terminator also throws 404 if no order reaches it.View complete source
findOrdersRoute
Implementation
Endpoint: GET /orders
Finds orders from validated query fields. The pagination wrapper is part of the route pipeline.
Access: Authenticated administrator, or an authenticated identity whose ID equals query identityId.
Request: findOrdersSchema accepts the documented filters and pagination query parameters; it has no body.
Pipeline: findOrders → normalizeOrdersListTerminator, wrapped by withPagination(...) and logging.
Success: Default Express JSON behavior produces 200 with { data, metadata: { pagination } }; _id is removed from each order.
Failure: The handler turns database failure into 500; the list terminator throws 500 if the pipeline did not produce a supported list shape.View complete source
updateOrderRoute
Implementation
Endpoint: PATCH /orders/:orderId
Updates an order, rereads it, and returns the normalized result.
Access: Authenticated administrator, or an authenticated identity that owns the order.
Request: updateOrderSchema requires path orderId and an application/json body; the schema permits an empty object, but the handler rejects an empty body.
Pipeline: updateOrder → getOrderById → normalizeOrderTerminator.
Success: Default Express JSON behavior produces 200 with the updated order, without _id.
Failure: updateOrder reports missing ID or body (400), no matching order (404), no modification (400), and database failure (500); the reread and normalizer have their documented 400/404/500 behavior.View complete source
deleteOrderRoute
Implementation
Endpoint: DELETE /orders/:orderId
Deletes one order.
Access: Authenticated administrator, or an authenticated identity that owns the order.
Request: deleteOrderSchema requires path orderId; there is no request body.
Pipeline: deleteOrder → deleteOrderTerminator.
Success: 204; its descriptor has no data, so the service calls res.status(204).json(undefined).
Failure: The delete handler reports missing ID (400), an absent order (404), or deletion/database failure (500); the terminator throws 500 if the deletion flag is absent.View complete source
findOrdersByOrganizationIdRoute
Implementation
Endpoint: GET /orders/organizations/:organizationId
Finds paginated orders for one organization through the reusable database block path.
Access: Authenticated identity with owner, admin, or member role in the path organization.
Request: findByOrganizationIdSchema requires organizationId and validates its pagination query parameters.
Pipeline: buildOrganizationIdFilter → buildWithoutMongoIdFindOptions → findOrders → applySpec(...) → orThrow(...). The block lookup is wrapped in pagination and logging.
Success: Default Express JSON behavior produces 200 with { data, metadata: { pagination } }. buildWithoutMongoIdFindOptions removes _id in the database projection.
Failure: orThrow maps an OrderDbBlockError from the block to 500; validator failures occur before this pipeline.View complete source