Skip to main content
Version: 🚧 Canary

⚙️ Product handlers

Product 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
createProductHandlerrequestBody, db.productsCreates a base entity and writes productId; 400 for an empty body or failed insert, 500 for database failure.createProductRoute
createProductBatchHandlerArray requestBody, db.productsCreates base entities and writes productIds; 400 for invalid input or count mismatch, 500 for database failure.createProductBatchRoute
getProductByIdHandlercontext.data.productId or path productId, db.productsWrites product; 400 when the ID is absent, 404 when no product exists, 500 for database failure.Custom composition only
getProductsByIdsHandlercontext.data.productIds or requestBody, db.productsWrites products; 400 when IDs are absent or not an array, 404 when no products match, 500 for database failure.createProductBatchRoute, updateProductBatchRoute, copyProductBatchRoute
findProductsHandlerrequestQuery, db.productsWrites products from query filter or empty filter; 500 for database failure.Custom composition only
updateProductHandlerPath/context product ID, requestBody, db.productsUpdates with updateBaseEntity and writes updateProductId; 400 for missing input or no modification, 404 for no match, 500 for database failure.updateProductRoute
updateProductBatchHandlerProduct IDs, update data, db.productsUpdates matching IDs and writes productIds; 400 for missing or empty input or no modification, 404 for no match, 500 for database failure.updateProductBatchRoute
copyProductHandlerPath/context product ID, db.productsCopies the source without _id and writes a new productId; 400 for a missing ID or failed insert, 404 when absent, 500 for database failure.copyProductRoute
copyProductBatchHandlerProduct IDs, db.productsCopies found products without _id and writes new productIds; 400 for invalid IDs or insert-count mismatch, 404 when none match, 500 for database failure.copyProductBatchRoute
deleteProductHandlerPath/context product ID, db.productsWrites deleteProduct; 400 for no ID, 404 for no deletion, 500 for database failure.deleteProductRoute
deleteProductBatchHandlerProduct IDs, db.productsWrites deleteProducts; 400 for invalid IDs or no deletions, 500 for database failure.deleteProductBatchRoute
normalizeProductTerminatorTerminatorPrior pipeline result, context.data.productRemoves _id and returns the product; throws error result or 500 when product data is absent.Custom composition only
normalizeProductsListTerminatorTerminatorPrior pipeline result, context.data.productsRemoves _id from an array or paginated data, preserving pagination metadata; throws error result on failure.Custom composition only
deleteProductTerminatorTerminatorPrior pipeline result, context.data.deleteProductReturns { statusCode: 204 }; throws error result or 500 when deletion data is absent.Custom composition only
deleteBatchProductsTerminatorTerminatorPrior pipeline result, context.data.deleteProductsReturns { statusCode: 204 }; throws error result or 500 when deletion data is absent.deleteProductBatchRoute

Details

createProduct

Implementation

Reads params.requestBody and context.db.products; writes context.data.productId. Requires a non-empty body; creates a base entity. Returns 400 for an empty body or failed insert and 500 for database failure. Used by createProductRoute

createProductBatch

Implementation

Reads an array from params.requestBody and context.db.products; writes context.data.productIds. Requires a non-empty array; creates base entities in one insert. Returns 400 for invalid input/count mismatch and 500 for database failure. Used by createProductBatchRoute

getProductById

Implementation

Reads context.data.productId or params.requestParams.productId and context.db.products; writes context.data.product. Returns 400 when the ID is absent, 404 when no product exists, and 500 for database failure. Used by Custom composition only.

getProductsByIds

Implementation

Reads context.data.productIds or params.requestBody and context.db.products; writes context.data.products. Returns 400 when IDs are absent/not an array, 404 when no products match, and 500 for database failure. Used by createProductBatchRoute, updateProductBatchRoute, copyProductBatchRoute

findProducts

Implementation

Reads params.requestQuery and context.db.products; writes context.data.products. Queries with the request filter or an empty filter; returns 500 for database failure. Used by Custom composition only.

updateProduct

Implementation

Reads context.data.productId or params.requestParams.productId, params.requestBody, and context.db.products; writes context.data.updateProductId. Updates with updateBaseEntity; returns 400 for missing input or no modification, 404 for no match, and 500 for database failure. Used by updateProductRoute

updateProductBatch

Implementation

Reads context.data.productIds or params.requestBody.ids, data from context.data.data or params.requestBody.data, and context.db.products; writes context.data.productIds. Updates all matching IDs with updateBaseEntity; returns 400 for missing/empty input or no modification, 404 for no match, and 500 for database failure. Used by updateProductBatchRoute

copyProduct

Implementation

Reads context.data.productId or params.requestParams.productId and context.db.products; writes a new context.data.productId. Copies the source without _id into a new base entity. Returns 400 for a missing ID/failed insert, 404 when absent, and 500 for database failure. Used by copyProductRoute

copyProductBatch

Implementation

Reads context.data.productIds or params.requestBody and context.db.products; writes new context.data.productIds. Copies all found products without _id. Returns 400 for invalid IDs or insert-count mismatch, 404 when none match, and 500 for database failure. Used by copyProductBatchRoute

deleteProduct

Implementation

Reads context.data.productId or params.requestParams.productId and context.db.products; writes context.data.deleteProduct. Deletes one product. Returns 400 for no ID, 404 for no deletion, and 500 for database failure. Used by deleteProductRoute

deleteProductBatch

Implementation

Reads context.data.productIds or params.requestBody and context.db.products; writes context.data.deleteProducts. Deletes matching IDs. Returns 400 for invalid IDs or no deletions and 500 for database failure. Used by deleteProductBatchRoute

normalizeProductTerminator

Implementation

Reads the Result value and context.data.product. Throws an error result; otherwise removes _id and returns the product. Throws 500 when product data is absent. Used by Custom composition only.

normalizeProductsListTerminator

Implementation

Reads the Result value and context.data.products. Throws an error result; otherwise removes _id from an array or paginated data, preserving pagination metadata. Used by Custom composition only.

deleteProductTerminator

Implementation

Reads the Result value and context.data.deleteProduct. Throws an error result or 500 when deletion data is absent; otherwise returns { statusCode: 204 }. Used by Custom composition only.

deleteBatchProductsTerminator

Implementation

Reads the Result value and context.data.deleteProducts. Throws an error result or 500 when deletion data is absent; otherwise returns { statusCode: 204 }. Used by deleteProductBatchRoute