📂 Category Feature Blocks
Category feature blocks provide complete, pre-composed functionality for category management operations in Nodeblocks applications. These features combine schemas, routes, and handlers to create ready-to-use API endpoints for category CRUD operations, status management, and hierarchical organization.
🎯 Overview
Category feature blocks are designed to:
- Provide complete category management with full CRUD operations
- Support hierarchical organization with parent-child relationships
- Handle category status management (enable/disable operations)
- Include validation and routing for secure operations
- Support filtering and pagination for category listings
📋 Feature Structure
Each category feature follows a consistent composition pattern:
- Schema: Validates category input data and parameters
- Route: Provides HTTP endpoint with category handlers
- Composition: Combines schema and route using
compose
function
🔧 Available Category Features
createCategoryFeature
Creates a new category with validation and routing.
Purpose: Handles category creation with complete validation
Composition:
- Schema:
createCategorySchema
- validates name, description, status, and optional parent - Route:
createCategoryRoute
- POST/categories
with creation handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.createCategoryFeature, [{ dataStores: db }])));
API Endpoint: POST /api/categories
getCategoryFeatures
Retrieves individual category data with access control.
Purpose: Fetches category information with proper validation
Composition:
- Schema:
getCategorySchema
- validates path parameters - Route:
getCategoryRoute
- GET/categories/:categoryId
with retrieval handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.getCategoryFeatures, [{ dataStores: db }])));
API Endpoint: GET /api/categories/:categoryId
findCategoriesFeatures
Searches and lists categories with filtering and pagination.
Purpose: Provides category listing with search capabilities
Composition:
- Schema:
findCategoriesSchema
- validates query parameters for filtering - Route:
findCategoriesRoute
- GET/categories
with search and pagination
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.findCategoriesFeatures, [{ dataStores: db }])));
API Endpoint: GET /api/categories
editCategoryFeatures
Updates category data with validation and access control.
Purpose: Modifies category information with proper validation
Composition:
- Schema:
updateCategorySchema
- validates optional name, description, and parent - Route:
updateCategoryRoute
- PATCH/categories/:categoryId
with update handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.editCategoryFeatures, [{ dataStores: db }])));
API Endpoint: PATCH /api/categories/:categoryId
enableCategoryStatusFeatures
Enables disabled categories to restore visibility.
Purpose: Activates category visibility and functionality
Composition:
- Schema:
enableCategorySchema
- validates path parameters - Route:
enableCategoryRoute
- POST/categories/:categoryId/enable
with enable handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.enableCategoryStatusFeatures, [{ dataStores: db }])));
API Endpoint: POST /api/categories/:categoryId/enable
disableCategoryStatusFeatures
Disables enabled categories to hide from listings.
Purpose: Deactivates category visibility and functionality
Composition:
- Schema:
disableCategorySchema
- validates path parameters - Route:
disableCategoryRoute
- POST/categories/:categoryId/disable
with disable handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.disableCategoryStatusFeatures, [{ dataStores: db }])));
API Endpoint: POST /api/categories/:categoryId/disable
editCategoryStatusFeatures
Combines enable and disable operations for category status management.
Purpose: Provides complete category status management functionality
Composition:
- Features:
enableCategoryStatusFeatures
,disableCategoryStatusFeatures
- combines both status operations
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.editCategoryStatusFeatures, [{ dataStores: db }])));
API Endpoints:
POST /api/categories/:categoryId/enable
- Enable categoryPOST /api/categories/:categoryId/disable
- Disable category
deleteCategoryFeatures
Deletes categories with proper validation and cleanup.
Purpose: Removes categories with access control and cleanup
Composition:
- Schema:
deleteCategorySchema
- validates path parameters - Route:
deleteCategoryRoute
- DELETE/categories/:categoryId
with deletion handler
Usage:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.deleteCategoryFeatures, [{ dataStores: db }])));
API Endpoint: DELETE /api/categories/:categoryId