🚀 ユーザー機能
ユーザー機能は、Nodeblocksアプリケーションでユーザー管理操作のための完全な、事前コンポーズされた機能を提供します。これらの機能は、スキーマ、ルート、ハンドラーを組み合わせて、適切なバリデーション、認証、エラー処理を含むすぐに使用できるAPIエンドポイントを作成します。
🎯 概要
ユーザー機能は以下の目的で設計されています:
- 完全なAPIエンドポイントの提供 - ユーザー管理操作用
- スキーマとルートの組み合わせ - バリデーション付き操作のため
- 認証と認可チェックの自動含める - 認証と認可チェックを自動的に含む
- 関数型コンポジションパターンのサポート - 関数型コンポジションパターンをサポート
- ロギングとエラー管理のシームレスな処理 - ロギングとエラー管理をシームレスに処理
📋 機能構造
各ユーザー機能は一貫したコンポジションパターンに従います:
- Schema: 入力データとパラメータをバリデーションします
- Route: ハンドラー付きHTTPエンドポイントを提供します
- コンポジション:
compose関数を使用してスキーマとルートを組み合わせます
🔧 利用可能なユーザー機能
createUserFeature
バリデーションとルーティング付きで新しいユーザーアカウントを作成します。
目的: 完全なバリデーション付きでユーザー登録を処理します
コンポジション:
- Schema:
createUserSchema- メール、名前、ステータスをバリデーションします - Route:
createUserRoute- 作成ハンドラー付きPOST/users
使用例:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.createUserFeature, [{ dataStores: db }])));
APIエンドポイント: POST /api/users
getUserFeatures
アクセス制御付きで個別のユーザーデータを取得します。
目的: 適切な認可付きでユーザープロフィールデータを取得します
コンポジション:
- Schema:
getUserSchema- パスパラメータをバリデーションします - Route:
getUserRoute- 取得ハンドラー付きGET/users/:profileId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.getUserFeatures, [{ dataStores: db }])));
APIエンドポイント: GET /api/users/:profileId
findUsersFeatures
フィルタリングとページネーション付きでユーザーを検索してリスト表示します。
目的: 検索機能付きでユーザーリストを提供します
コンポジション:
- Schema:
findUsersSchema- フィルタリング用のクエリパラメータをバリデーションします - Route:
findUsersRoute- 検索とページネーション付きGET/users
使用例:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.findUsersFeatures, [{ dataStores: db }])));
APIエンドポイント: GET /api/users
editUserFeatures
バリデーションとアクセス制御付きでユーザープロフィールデータを更新します。
目的: 適切な認可付きでユーザーデータを変更します
コンポジション:
- Schema:
updateUserSchema- 部分的なユーザープロパティをバリデーションします - Route:
updateUserRoute- 更新ハンドラー付きPATCH/users/:profileId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.editUserFeatures, [{ dataStores: db }])));
APIエンドポイント: PATCH /api/users/:profileId
deleteUserFeatures
適切な認可付きでユーザーアカウントを削除します。
目的: アクセス制御付きでユーザーアカウントを削除します
コンポジション:
- Schema:
deleteUserSchema- パスパラメータをバリデーションします - Route:
deleteUserRoute- 削除ハンドラー付きDELETE/users/:profileId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// With database configuration
app.use('/api', defService(partial(features.deleteUserFeatures, [{ dataStores: db }])));
APIエンドポイント: DELETE /api/users/:profileId
getAvatarUploadUrlFeature
スキーマバリデーションとルーティング付きのユーザーアバターアップロードURL生成機能。
目的: 自動UUIDファイル名生成付きでセキュアなアバターファイルアップロード用の事前署名付きURLを生成します
コンポジション:
- Schema:
getSignedImageUploadUrlSchema- 画像アップロード用のコンテンツタイプとファイルサイズをバリデーションします - Route:
getAvatarUploadUrlRoute- 署名付きURL生成付きGET/user-profiles/:profileId/avatar-upload-url
使用例:
import { features } from '@nodeblocks/backend-sdk';
// With file storage service in configuration:
app.use('/api', defService(partial(features.getAvatarUploadUrlFeature, [{ configuration: { fileStorageDriver } }])));
APIエンドポイント: GET /api/user-profiles/:profileId/avatar-upload-url
findProfilesByIdentityIdFeature
スキーマバリデーションとルーティング付きのID別ユーザープロフィール取得機能。
目的: アバター正規化と自己アクセス制御付きで特定のIDに関連付けられたページネーションされたユーザープロフィールを取得します
コンポジション:
- Schema:
findByIdentityIdSchema- ページネーションサポート付きでidentityIdパスパラメータをバリデーションします - Route:
findProfilesByIdentityIdRoute- プロフィール取得とアバター処理付きGET/profiles/identities/:identityId
使用例:
import { features } from '@nodeblocks/backend-sdk';
// Direct usage:
app.use('/api', defService(findProfilesByIdentityIdFeature));
// With database configuration
app.use('/api', defService(partial(findProfilesByIdentityIdFeature, [{ dataStores: db }])));
APIエンドポイント: GET /api/profiles/identities/:identityId
レスポンスフォーマット:
{
"data": [
{
"id": "profile-123",
"name": "John Doe",
"avatar": {
"url": "https://cdn.example.com/avatars/profile-123.jpg",
"type": "image/jpeg"
},
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
],
"metadata": {
"pagination": {
"hasNext": false,
"hasPrev": false,
"limit": 10,
"page": 1,
"total": 1,
"totalPages": 1
}
}
}
認可: 認証と自己アクセスが必要です(ユーザーはID別に自分のプロフィールのみを表示できます)