メインコンテンツまでスキップ
バージョン: 0.9.0 (最新)

🛣️ カテゴリルート

カテゴリルートは、Nodeblocksアプリケーションでカテゴリ管理操作のための事前設定されたHTTPエンドポイントを提供します。これらのルートは、ハンドラー、バリデーター、ミドルウェアを組み合わせて、適切な認証、認可、エラー処理を持つ完全なAPIエンドポイントを作成します。


🎯 概要

カテゴリルートは以下の目的で設計されています:

  • カテゴリ管理操作のための完全なAPIエンドポイントを提供
  • 安全な操作のためにハンドラーとバリデーターを組み合わせる
  • 認証と認可チェックを含む
  • 関数合成パターンをサポート
  • ロギングとエラー管理を自動的に処理

📋 ルート構造

各カテゴリルートは一貫したパターンに従います:

  • HTTPメソッド: 操作タイプを定義(GET、POST、PATCH、DELETE)
  • パス: パラメータ付きエンドポイントURLを指定
  • ハンドラー: ビジネスロジック用の合成関数チェーン
  • バリデーター: 認証と認可チェック

🔧 利用可能なカテゴリルート

createCategoryRoute

新しいカテゴリを作成し、作成されたリソースを返します。

目的: カテゴリの作成を処理

ルート詳細:

  • Method: POST
  • Path: /categories
  • 認証: 必須(Bearerトークン)

ハンドラー: createCategory, getCategoryById, normalizeCategoryTerminator

バリデーター: isAuthenticated, checkIdentityType(['admin'])

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.createCategoryRoute);

getCategoryRoute

存在検証でIDで特定のカテゴリを取得します。

目的: バリデーションでカテゴリデータを取得

ルート詳細:

  • Method: GET
  • Path: /categories/:categoryId
  • 認証: 不要

ハンドラー: getCategoryById, normalizeCategoryTerminator

バリデーター: doesCategoryExist

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.getCategoryRoute);

findCategoriesRoute

正規化されたリスト形式ですべてのカテゴリを取得します。

目的: ページネーションでカテゴリをリスト表示

ルート詳細:

  • Method: GET
  • Path: /categories
  • 認証: 不要

ハンドラー: findCategories, normalizeCategoriesListTerminator

バリデーター: なし

クエリパラメータ

  • description?: string
  • name?: string
  • parent?: string
  • status?: string
  • page?: number
  • limit?: number

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.findCategoriesRoute);

updateCategoryRoute

既存のカテゴリを更新し、更新されたリソースを返します。

目的: カテゴリデータを変更

ルート詳細:

  • Method: PATCH
  • Path: /categories/:categoryId
  • 認証: 必須(Bearerトークン)

ハンドラー: updateCategory, getCategoryById, normalizeCategoryTerminator

バリデーター: isAuthenticated, checkIdentityType(['admin']), doesCategoryExist

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.updateCategoryRoute);

deleteCategoryRoute

存在検証でIDでカテゴリを削除します。

目的: カテゴリを削除

ルート詳細:

  • Method: DELETE
  • Path: /categories/:categoryId
  • 認証: 必須(Bearerトークン)

ハンドラー: deleteCategory, deleteCategoryTerminator

バリデーター: isAuthenticated, checkIdentityType(['admin']), doesCategoryExist

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.deleteCategoryRoute);

enableCategoryRoute

存在検証でIDでカテゴリを有効化します。

目的: カテゴリステータスを有効化

ルート詳細:

  • Method: POST
  • Path: /categories/:categoryId/enable
  • 認証: 必須(Bearerトークン)

ハンドラー: enableCategory, enableCategoryTerminator

バリデーター: isAuthenticated, checkIdentityType(['admin']), doesCategoryExist

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.enableCategoryRoute);

disableCategoryRoute

存在検証でIDでカテゴリを無効化します。

目的: カテゴリステータスを無効化

ルート詳細:

  • Method: POST
  • Path: /categories/:categoryId/disable
  • 認証: 必須(Bearerトークン)

ハンドラー: disableCategory, disableCategoryTerminator

バリデーター: isAuthenticated, checkIdentityType(['admin']), doesCategoryExist

使用例:

import { routes } from '@nodeblocks/backend-sdk';

// Register route with Express app
app.use('/api', routes.disableCategoryRoute);