✅ Category validators
Category routes compose the direct category-existence guard with shared authentication and administrator checks.
Inventory
| Validator | Reads | Success condition | Failure / error | Consumers |
|---|---|---|---|---|
doesCategoryExist | params.requestParams.categoryId, context.db.categories | A category with the ID exists. | 404 Category does not exist; database rejection reaches the service as 500. | getCategoryRoute, updateCategoryRoute, deleteCategoryRoute, enableCategoryRoute, disableCategoryRoute |
isAuthenticated() | context.authenticate, or Bearer-token fallback | Configured authentication succeeds. | Adapter-defined authentication failure. | createCategoryRoute, updateCategoryRoute, deleteCategoryRoute, enableCategoryRoute, disableCategoryRoute |
checkIdentityType(['admin']) | Auth adapter, identities, configuration.identity.typeIds | Identity typeId equals configured admin ID. | 500, 401, or 403 by failed prerequisite. | createCategoryRoute, updateCategoryRoute, deleteCategoryRoute, enableCategoryRoute, disableCategoryRoute |
Details
doesCategoryExist
Implementation
This is a direct validator: use doesCategoryExist, not doesCategoryExist(). It looks up String(params.requestParams?.categoryId) in context.db.categories and throws NodeblocksError(404, 'Category does not exist') when no record exists. It does not catch a database rejection, so defService converts that rejection to a 500 service error.
Consumers: getCategoryRoute, updateCategoryRoute, deleteCategoryRoute, enableCategoryRoute, and disableCategoryRoute.
isAuthenticated()
Implementation
Shared factory validator. It calls context.authenticate(payload) when configured; otherwise it uses the SDK Bearer-token adapter. The adapter determines the authentication error returned to the client.
Consumers: createCategoryRoute, updateCategoryRoute, deleteCategoryRoute, enableCategoryRoute, and disableCategoryRoute. See the Authentication validator reference.
checkIdentityType(['admin'])
Implementation
Shared factory validator. It requires db.identities and configuration.identity.typeIds, authenticates the request, loads the identity, and compares its typeId to typeIds.admin. Missing configuration is 500; an invalid token is 401; an unavailable, malformed, or non-admin identity is 403.
Consumers: createCategoryRoute, updateCategoryRoute, deleteCategoryRoute, enableCategoryRoute, and disableCategoryRoute. See the Authentication validator reference.