🪪 Category Validators
Category validators provide validation functions for category-related operations in Nodeblocks applications. These validators ensure data integrity and proper business logic validation for category operations.
🎯 Overview
Category validators are designed to:
- Validate category existence before operations
- Ensure data integrity in category workflows
- Provide reusable validation logic for category operations
- Support composition with other category blocks
- Handle error cases with proper error responses
📋 Category Validator Types
Existence Validators
Validators that check if categories exist in the database.
🔧 Available Category Validators
doesCategoryExist
Validates that a category exists in the database by checking the categoryId parameter.
Purpose: Ensures the requested category exists before proceeding with operations
Parameters:
payload: RouteHandlerPayload containing context and paramspayload.context.db: Database connection with categories collectionpayload.params.requestParams.categoryId: Category ID to validate
Returns: void - Passes through if category exists
Throws: NodeblocksError (404) with message "Category does not exist" if category not found
Usage:
import { validators } from '@nodeblocks/backend-sdk';
const { doesCategoryExist } = validators;
withRoute({
-- snip --
validators: [doesCategoryExist]
});
🔗 Related Documentation
- Category Schemas - Category data validation and contracts
- Category Handlers - Category business logic functions
- Category Routes - Category HTTP endpoint definitions
- Category Features - Category composed features