Skip to main content
Version: 0.13.0 (Previous)

⚙️ Category handlers

Category 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
createCategoryHandlerNon-empty requestBody, context.db.categoriesWrites categoryId; creates base entity; 400 or 500 on failure.createCategoryRoute
getCategoryByIdHandlercontext.data.categoryId or path categoryId, context.db.categoriesWrites category; 400, 404, or 500 on failure.createCategoryRoute, getCategoryRoute, updateCategoryRoute
findCategoriesHandlerrequestQuery, context.db.categoriesWrites matching categories; 500 on query failure.findCategoriesRoute
updateCategoryHandlerCategory ID, non-empty requestBody, context.db.categoriesUpdates base-entity fields and writes update result; 400, 404, or 500.updateCategoryRoute
deleteCategoryHandlerCategory ID, context.db.categoriesDeletes matching category and writes delete result; 400, 404, or 500.deleteCategoryRoute
enableCategoryHandlerCategory ID, context.db.categoriesSets status to 'active'; 400, 404, or 500.enableCategoryRoute
disableCategoryHandlerCategory ID, context.db.categoriesSets status to 'inactive'; 400, 404, or 500.disableCategoryRoute
normalizeCategoryTerminatorTerminatorcontext.data.categoryRemoves _id and returns one category; missing data is 500.createCategoryRoute, getCategoryRoute, updateCategoryRoute
normalizeCategoriesListTerminatorTerminatorcontext.data.categoriesRemoves _id and preserves pagination metadata; invalid shape is 500.findCategoriesRoute
deleteCategoryTerminatorTerminatorcontext.data.deleteCategoryReturns { statusCode: 204 }; missing data is 500.deleteCategoryRoute
enableCategoryTerminatorTerminatorcontext.data.enableCategoryReturns { statusCode: 204 }; missing data is 500.enableCategoryRoute
disableCategoryTerminatorTerminatorcontext.data.disableCategoryReturns { statusCode: 204 }; missing data is 500.disableCategoryRoute

Details

createCategory

Implementation

Rejects a missing or empty body with 400, inserts createBaseEntity(requestBody), and writes its generated id as categoryId. Database failures and missing insertedId return 500 and 400, respectively. Used by createCategoryRoute.

getCategoryById

Implementation

Uses context.data.categoryId before the path parameter. A missing ID is 400, a database failure is 500, and no matching category is 404. Used by createCategoryRoute, getCategoryRoute, and updateCategoryRoute.

findCategories

Implementation

Passes requestQuery (or {}) directly to categories.find, converts the cursor to an array, and writes categories; a database failure is 500. In the exported route, withPagination removes page and limit before this handler and changes toArray() into a paginated { data, metadata } result. Used by findCategoriesRoute. Pagination is applied by that route's withPagination wrapper.

updateCategory

Implementation

Requires an ID and non-empty body, then applies updateBaseEntity(requestBody). Missing ID/body is 400; no match is 404; no modification is 400. Used by updateCategoryRoute.

deleteCategory

Implementation

Deletes by ID and writes deleteCategory. Missing ID is 400, no deletion is 404, and database failures are 500. Used by deleteCategoryRoute.

enableCategory

Implementation

Updates the category with updateBaseEntity({ status: 'active' }). Missing ID is 400, no match is 404, and an unchanged result is 500. Used by enableCategoryRoute.

disableCategory

Implementation

Updates the category with updateBaseEntity({ status: 'inactive' }). Missing ID is 400, no match is 404, and an unchanged result is 500. Used by disableCategoryRoute.

normalizeCategoryTerminator

Implementation

Throws the pipeline error, or a 500 when context.data.category is absent; otherwise returns the category without MongoDB _id. Used by createCategoryRoute, getCategoryRoute, and updateCategoryRoute.

normalizeCategoriesListTerminator

Implementation

Throws the pipeline error, or a 500 unless categories is an array or a paginated { data, metadata } value. It removes _id from every returned category. For the exported route, the paginated input is always normalized to { data, metadata: { pagination } }. Used by findCategoriesRoute.

deleteCategoryTerminator

Implementation

Throws the pipeline error or a 500 when deleteCategory is absent; otherwise returns { statusCode: 204 }. Used by deleteCategoryRoute.

enableCategoryTerminator

Implementation

Throws the pipeline error or a 500 when enableCategory is absent; otherwise returns { statusCode: 204 }. Used by enableCategoryRoute.

disableCategoryTerminator

Implementation

Throws the pipeline error or a 500 when disableCategory is absent; otherwise returns { statusCode: 204 }. Used by disableCategoryRoute.