⚙️ 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
| Handler | Pipeline role | Inputs / context | Result / behavior / errors | Used by routes |
|---|---|---|---|---|
createProduct | Handler | requestBody, db.products | Creates a base entity and writes productId; 400 for an empty body or failed insert, 500 for database failure. | createProductRoute |
createProductBatch | Handler | Array requestBody, db.products | Creates base entities and writes productIds; 400 for invalid input or count mismatch, 500 for database failure. | createProductBatchRoute |
getProductById | Handler | context.data.productId or path productId, db.products | Writes product; 400 when the ID is absent, 404 when no product exists, 500 for database failure. | Custom composition only |
getProductsByIds | Handler | context.data.productIds or requestBody, db.products | Writes products; 400 when IDs are absent or not an array, 404 when no products match, 500 for database failure. | createProductBatchRoute, updateProductBatchRoute, copyProductBatchRoute |
findProducts | Handler | requestQuery, db.products | Writes products from query filter or empty filter; 500 for database failure. | Custom composition only |
updateProduct | Handler | Path/context product ID, requestBody, db.products | Updates with updateBaseEntity and writes updateProductId; 400 for missing input or no modification, 404 for no match, 500 for database failure. | updateProductRoute |
updateProductBatch | Handler | Product IDs, update data, db.products | Updates matching IDs and writes productIds; 400 for missing or empty input or no modification, 404 for no match, 500 for database failure. | updateProductBatchRoute |
copyProduct | Handler | Path/context product ID, db.products | Copies 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 |
copyProductBatch | Handler | Product IDs, db.products | Copies 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 |
deleteProduct | Handler | Path/context product ID, db.products | Writes deleteProduct; 400 for no ID, 404 for no deletion, 500 for database failure. | deleteProductRoute |
deleteProductBatch | Handler | Product IDs, db.products | Writes deleteProducts; 400 for invalid IDs or no deletions, 500 for database failure. | deleteProductBatchRoute |
normalizeProductTerminator | Terminator | Prior pipeline result, context.data.product | Removes _id and returns the product; throws error result or 500 when product data is absent. | Custom composition only |
normalizeProductsListTerminator | Terminator | Prior pipeline result, context.data.products | Removes _id from an array or paginated data, preserving pagination metadata; throws error result on failure. | Custom composition only |
deleteProductTerminator | Terminator | Prior pipeline result, context.data.deleteProduct | Returns { statusCode: 204 }; throws error result or 500 when deletion data is absent. | Custom composition only |
deleteBatchProductsTerminator | Terminator | Prior pipeline result, context.data.deleteProducts | Returns { 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