📂 カテゴリ機能ブロック
カテゴリ機能ブロックは、NodeBlocks アプリケーションにおけるカテゴリ管理操作のための完全な事前構成済み機能を提供します。これらの機能は、スキーマ、ルート、ハンドラーを組み合わせ、カテゴリ CRUD 操作、ステータス管理、階層組織のための即使用可能な API エンドポイントを作成します。
🎯 概要
カテゴリ機能ブロックは次のことを目的として設計されています:
- 完全なカテゴリ管理を提供する(完全な CRUD 操作付き)
- 親子関係を使用した階層組織をサポートする
- カテゴリステータス管理を処理する(有効化/無効化操作)
- 安全な操作のための検証とルーティングを含む
- カテゴリリストのためのフィルタリングとページネーションをサポートする
📋 機能構造
各カテゴリ機能は一貫した構成パターンを従います:
- スキーマ: カテゴリ入力データとパラメーターを検証します
- ルート: カテゴリハンドラー付きの HTTP エンドポイントを提供します
- 構成:
compose
関数を使用してスキーマとルートを組み合わせます
🔧 利用可能なカテゴリ機能
createCategoryFeature
検証とルーティングを使用して新しいカテゴリを作成します。
目的: 完全な検証を使用してカテゴリ作成を処理します
構成:
- スキーマ:
createCategorySchema
- 名前、説明、ステータス、オプションの親を検証 - ルート:
createCategoryRoute
- 作成ハンドラー付きの POST/categories
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.createCategoryFeature));
// データベース構成を使用
app.use('/api', defService(partial(features.createCategoryFeature, [{ dataStores: db }])));
API エンドポイント: POST /api/categories
getCategoryFeatures
アクセス制御を使用して個別カテゴリデータを取得します。
目的: 適切な検証を使用してカテゴリ情報を取得します
構成:
- スキーマ:
getCategorySchema
- パスパラメーターを検証 - ルート:
getCategoryRoute
- 取得ハンドラー付きの GET/categories/:categoryId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.getCategoryFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.getCategoryFeatures, [{ dataStores: db }])));
API エンドポイント: GET /api/categories/:categoryId
findCategoriesFeatures
フィルタリングとページネーションを使用してカテゴリを検索およびリストします。
目的: 検索機能を使用してカテゴリリストを提供します
構成:
- スキーマ:
findCategoriesSchema
- フィルタリング用のクエリパラメーターを検証 - ルート:
findCategoriesRoute
- 検索とページネーション付きの GET/categories
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.findCategoriesFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.findCategoriesFeatures, [{ dataStores: db }])));
API エンドポイント: GET /api/categories
editCategoryFeatures
検証とアクセス制御を使用してカテゴリデータを更新します。
目的: 適切な検証を使用してカテゴリ情報を変更します
構成:
- スキーマ:
updateCategorySchema
- オプションの名前、説明、ステータス、親を検証 - ルート:
updateCategoryRoute
- 更新ハンドラー付きの PATCH/categories/:categoryId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.editCategoryFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.editCategoryFeatures, [{ dataStores: db }])));
API エンドポイント: PATCH /api/categories/:categoryId
enableCategoryStatusFeatures
無効化されたカテゴリを有効化して可視性を復元します。
Purpose: カテゴリの可視性と機能を有効化します
構成:
- スキーマ:
enableCategorySchema
- パスパラメーターを検証 - ルート:
enableCategoryRoute
- 有効化ハンドラー付きの POST/categories/:categoryId/enable
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.enableCategoryStatusFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.enableCategoryStatusFeatures, [{ dataStores: db }])));
API エンドポイント: POST /api/categories/:categoryId/enable
disableCategoryStatusFeatures
有効化されたカテゴリを無効化してリストから非表示にします。
目的: カテゴリの可視性と機能を無効化します
構成:
- スキーマ:
disableCategorySchema
- パスパラメーターを検証 - ルート:
disableCategoryRoute
- 無効化ハンドラー付きの POST/categories/:categoryId/disable
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.disableCategoryStatusFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.disableCategoryStatusFeatures, [{ dataStores: db }])));
API エンドポイント: POST /api/categories/:categoryId/disable
editCategoryStatusFeatures
カテゴリステータス管理のための有効化および無効化操作を組み合わせます。
目的: 完全なカテゴリステータス管理機能を提供します
構成:
- 機能:
enableCategoryStatusFeatures
,disableCategoryStatusFeatures
- 両方のステータス操作を組み合わせます
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.editCategoryStatusFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.editCategoryStatusFeatures, [{ dataStores: db }])));
API エンドポイント:
POST /api/categories/:categoryId/enable
- カテゴリを有効化POST /api/categories/:categoryId/disable
- カテゴリを無効化
deleteCategoryFeatures
適切な検証とクリーンアップを使用してカテゴリを削除します。
目的: アクセス制御とクリーンアップを使用してカテゴリを削除します
構成:
- スキーマ:
deleteCategorySchema
- パスパラメーターを検証 - ルート:
deleteCategoryRoute
- 削除ハンドラー付きの DELETE/categories/:categoryId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// 直接使用(ハンドラーで dataStores が必要)
app.use('/api', defService(features.deleteCategoryFeatures));
// データベース構成を使用
app.use('/api', defService(partial(features.deleteCategoryFeatures, [{ dataStores: db }])));
API エンドポイント: DELETE /api/categories/:categoryId