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

🛣️ カテゴリルート

カテゴリルートは Express ミドルウェアではなく SDK コンポーザです。公開された参照は HTTP を使用します;変更操作には認証に続き、設定された管理者アイデンティティチェックが必要です。

インベントリ

ルートメソッド / プロトコルパススキーマバリデータ成功ステータス
createCategoryRoutePOST / HTTP/categoriescreateCategorySchemaisAuthenticated()checkIdentityType(['admin'])200
getCategoryRouteGET / HTTP/categories/:categoryIdgetCategorySchemadoesCategoryExist200
findCategoriesRouteGET / HTTP/categoriesfindCategoriesSchemaなし200
updateCategoryRoutePATCH / HTTP/categories/:categoryIdupdateCategorySchemaisAuthenticated()checkIdentityType(['admin'])doesCategoryExist200
deleteCategoryRouteDELETE / HTTP/categories/:categoryIddeleteCategorySchemaisAuthenticated()checkIdentityType(['admin'])doesCategoryExist204
enableCategoryRoutePOST / HTTP/categories/:categoryId/enableenableCategorySchemaisAuthenticated()checkIdentityType(['admin'])doesCategoryExist204
disableCategoryRoutePOST / HTTP/categories/:categoryId/disabledisableCategorySchemaisAuthenticated()checkIdentityType(['admin'])doesCategoryExist204

詳細

createCategoryRoute

実装

エンドポイント: POST /categories

アクセス: 管理者;バリデータは isAuthenticated() 後に checkIdentityType(['admin']) を実行します。

リクエスト: 必須 application/json 作成ボディ、および設定された認証転送。

パイプライン: createCategorygetCategoryByIdnormalizeCategoryTerminator

成功: _id 削除後の作成されたカテゴリとともに 200;サービスは通常の res.json(result) ブランチを使用します。

失敗: スキーマ/ボディエラーとハンドラの 400/500 エラー;認証/認可の失敗は バリデータ で文書されています。

完全なソースを表示
export const createCategoryRoute = withRoute({
handler: compose(
withLogging(createCategory),
flatMapAsync(withLogging(getCategoryById)),
lift(withLogging(normalizeCategoryTerminator))
),
method: 'POST',
path: '/categories',
validators: [isAuthenticated(), checkIdentityType(['admin'])],
});

getCategoryRoute

実装

エンドポイント: GET /categories/:categoryId

アクセス: 公開;直接 doesCategoryExist が最初に実行されます。

リクエスト: 取得スキーマ の必須文字列 categoryId パス値。

パイプライン: getCategoryByIdnormalizeCategoryTerminator

成功: MongoDB _id なしで1件カテゴリとともに 200;サービスは通常の res.json(result) ブランチを使用します。

失敗: doesCategoryExist は欠損時に 404 を返します;捕捉されないデータベースの拒否はサービスにより 500 に変換されます。ルックアップはハンドラの 400404、または 500 エラーも返す場合があります。

完全なソースを表示
export const getCategoryRoute = withRoute({
handler: compose(
withLogging(getCategoryById),
lift(withLogging(normalizeCategoryTerminator))
),
method: 'GET',
path: '/categories/:categoryId',
validators: [doesCategoryExist],
});

findCategoriesRoute

実装

エンドポイント: GET /categories

アクセス: 公開。

リクエスト: オプションの descriptionnameparentstatus フィルターと pagelimit検索スキーマ から取得します。ページネーションはページ 1 とリミット 10 にデフォルトされます。

パイプライン: withPagination(findCategories) → normalizeCategoriesListTerminator

成功: サービスの通常の res.json(result) ブランチ経由で { data, metadata: { pagination } } とともに 200data には _id なしカテゴリが含まれます;ページネーションには pagelimittotaltotalPageshasNexthasPrev が含まれます。

失敗: データベースルックアップの失敗は 500 を返します。

完全なソースを表示
export const findCategoriesRoute = withRoute({
handler: compose(
withPagination(withLogging(findCategories)),
lift(withLogging(normalizeCategoriesListTerminator))
),
method: 'GET',
path: '/categories',
validators: [],
});

updateCategoryRoute

実装

エンドポイント: PATCH /categories/:categoryId

アクセス: 管理者;バリデータは isAuthenticated()checkIdentityType(['admin'])doesCategoryExist を実行します。

リクエスト: categoryId、設定された認証転送、および 更新スキーマ からの必須 application/json 部分更新ボディ。

パイプライン: updateCategorygetCategoryByIdnormalizeCategoryTerminator

成功: 更新後に取得された正規化されたカテゴリとともに 200;サービスは通常の res.json(result) ブランチを使用します。

失敗: 空/欠損ボディは 400;存在しないカテゴリは 404 で拒否されます;変更なしの更新は 400 です;バリデータ で共有アクセスの失敗を参照してください。

完全なソースを表示
export const updateCategoryRoute = withRoute({
handler: compose(
withLogging(updateCategory),
flatMapAsync(withLogging(getCategoryById)),
lift(withLogging(normalizeCategoryTerminator))
),
method: 'PATCH',
path: '/categories/:categoryId',
validators: [
isAuthenticated(),
checkIdentityType(['admin']),
doesCategoryExist,
],
});

deleteCategoryRoute

実装

エンドポイント: DELETE /categories/:categoryId

アクセス: 管理者;isAuthenticated()checkIdentityType(['admin'])doesCategoryExist

リクエスト: categoryId と設定された認証転送;削除スキーマ はボディを定義しません。

パイプライン: deleteCategorydeleteCategoryTerminator

成功: 空の 204 レスポンス。

失敗: 存在しないカテゴリは 404;削除の失敗は 500;アクセスの失敗は バリデータ で説明されています。

完全なソースを表示
export const deleteCategoryRoute = withRoute({
handler: compose(
withLogging(deleteCategory),
lift(withLogging(deleteCategoryTerminator))
),
method: 'DELETE',
path: '/categories/:categoryId',
validators: [
isAuthenticated(),
checkIdentityType(['admin']),
doesCategoryExist,
],
});

enableCategoryRoute

実装

エンドポイント: POST /categories/:categoryId/enable

アクセス: 管理者;isAuthenticated()checkIdentityType(['admin'])doesCategoryExist

リクエスト: categoryId と設定された認証転送;有効化スキーマ はボディを定義しません。

パイプライン: enableCategoryenableCategoryTerminator

成功: status'active' に設定された後、空の 204 レスポンス。

失敗: 存在しないカテゴリは 404;変更なしの更新またはデータベースエラーは 500 です。

完全なソースを表示
export const enableCategoryRoute = withRoute({
handler: compose(
withLogging(enableCategory),
lift(withLogging(enableCategoryTerminator))
),
method: 'POST',
path: '/categories/:categoryId/enable',
validators: [
isAuthenticated(),
checkIdentityType(['admin']),
doesCategoryExist,
],
});

disableCategoryRoute

実装

エンドポイント: POST /categories/:categoryId/disable

アクセス: 管理者;isAuthenticated()checkIdentityType(['admin'])doesCategoryExist

リクエスト: categoryId と設定された認証転送;無効化スキーマ はボディを定義しません。

パイプライン: disableCategorydisableCategoryTerminator

成功: status'inactive' に設定された後、空の 204 レスポンス。

失敗: 存在しないカテゴリは 404;変更なしの更新またはデータベースエラーは 500 です。

完全なソースを表示
export const disableCategoryRoute = withRoute({
handler: compose(
withLogging(disableCategory),
lift(withLogging(disableCategoryTerminator))
),
method: 'POST',
path: '/categories/:categoryId/disable',
validators: [
isAuthenticated(),
checkIdentityType(['admin']),
doesCategoryExist,
],
});