From 17640eefa12c676976081f37184fa92ab1816c3e Mon Sep 17 00:00:00 2001 From: "oura.a" Date: Mon, 4 Sep 2023 08:37:01 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20382:=20API=20IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2542: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2542) パートナー取得APIのIFを実装しました。 ## レビューポイント なし ## UIの変更 なし ## 動作確認状況 ローカルでSwaggerUiを確認 ## 補足 なし --- dictation_server/src/api/odms/openapi.json | 99 +++++++++++++++++++ .../features/accounts/accounts.controller.ts | 84 ++++++++++++++++ .../src/features/accounts/types/types.ts | 35 +++++++ 3 files changed, 218 insertions(+) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 9c9111f..8618769 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -838,6 +838,64 @@ "security": [{ "bearer": [] }] } }, + "/accounts/partners": { + "get": { + "operationId": "getPartners", + "summary": "", + "parameters": [ + { + "name": "limit", + "required": true, + "in": "query", + "description": "取得件数", + "schema": { "type": "number" } + }, + { + "name": "offset", + "required": true, + "in": "query", + "description": "開始位置", + "schema": { "type": "number" } + } + ], + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/GetPartnersResponse" } + } + } + }, + "400": { + "description": "パラメータ不正", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorResponse" } + } + } + }, + "401": { + "description": "認証エラー", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorResponse" } + } + } + }, + "500": { + "description": "想定外のサーバーエラー", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/ErrorResponse" } + } + } + } + }, + "tags": ["accounts"], + "security": [{ "bearer": [] }] + } + }, "/users/confirm": { "post": { "operationId": "confirmUser", @@ -2767,6 +2825,47 @@ "required": ["worktypeId"] }, "CreateWorktypeResponse": { "type": "object", "properties": {} }, + "Partner": { + "type": "object", + "properties": { + "name": { "type": "string", "description": "会社名" }, + "tier": { "type": "number", "description": "階層" }, + "accountId": { "type": "number", "description": "アカウントID" }, + "country": { "type": "string", "description": "国" }, + "primaryAdmin": { + "type": "string", + "description": "プライマリ管理者" + }, + "email": { + "type": "string", + "description": "プライマリ管理者メールアドレス" + }, + "dealerManagement": { + "type": "boolean", + "description": "代行操作許可" + } + }, + "required": [ + "name", + "tier", + "accountId", + "country", + "primaryAdmin", + "email", + "dealerManagement" + ] + }, + "GetPartnersResponse": { + "type": "object", + "properties": { + "total": { "type": "number", "description": "合計件数" }, + "partners": { + "type": "array", + "items": { "$ref": "#/components/schemas/Partner" } + } + }, + "required": ["total", "partners"] + }, "ConfirmRequest": { "type": "object", "properties": { "token": { "type": "string" } }, diff --git a/dictation_server/src/features/accounts/accounts.controller.ts b/dictation_server/src/features/accounts/accounts.controller.ts index 94cbf6d..3dd6f6e 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -7,6 +7,7 @@ import { Req, UseGuards, Param, + Query, } from '@nestjs/common'; import { ApiOperation, @@ -45,6 +46,8 @@ import { GetWorktypesResponse, CreateWorktypeResponse, CreateWorktypesRequest, + GetPartnersRequest, + GetPartnersResponse, } from './types/types'; import { USER_ROLES, ADMIN_ROLES, TIERS } from '../../constants'; import { AuthGuard } from '../../common/guards/auth/authguards'; @@ -715,4 +718,85 @@ export class AccountsController { return {}; } + + @Get('/partners') + @ApiResponse({ + status: HttpStatus.OK, + type: GetPartnersResponse, + description: '成功時のレスポンス', + }) + @ApiResponse({ + status: HttpStatus.BAD_REQUEST, + description: 'パラメータ不正', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.UNAUTHORIZED, + description: '認証エラー', + type: ErrorResponse, + }) + @ApiResponse({ + status: HttpStatus.INTERNAL_SERVER_ERROR, + description: '想定外のサーバーエラー', + type: ErrorResponse, + }) + @ApiOperation({ operationId: 'getPartners' }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards( + RoleGuard.requireds({ + roles: [ADMIN_ROLES.ADMIN], + tiers: [TIERS.TIER1, TIERS.TIER2], + }), + ) + async getPartners( + @Req() req: Request, + @Query() query: GetPartnersRequest, + ): Promise { + const { limit, offset } = query; + const token = retrieveAuthorizationToken(req); + const { userId } = jwt.decode(token, { json: true }) as AccessToken; + + const context = makeContext(userId); + // TODO: パートナー取得APIで実装 + // await this.accountService.getPartners( + // context, + // body.limit, + // body.offset, + // ); + + // 仮のreturn + return { + total: 1, + partners: [ + { + name: 'testA', + tier: 5, + accountId: 1, + country: 'US', + primaryAdmin: 'nameA', + email: 'aaa@example.com', + dealerManagement: true, + }, + { + name: 'testB', + tier: 5, + accountId: 2, + country: 'US', + primaryAdmin: 'nameB', + email: 'bbb@example.com', + dealerManagement: false, + }, + { + name: 'testC', + tier: 5, + accountId: 1, + country: 'US', + primaryAdmin: 'nothing', + email: 'nothing', + dealerManagement: false, + }, + ], + }; + } } diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index a828112..4b54066 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -361,3 +361,38 @@ export class CreateWorktypesRequest { } export class CreateWorktypeResponse {} + +export class GetPartnersRequest { + @ApiProperty({ description: '取得件数' }) + @IsInt() + @Min(0) + limit: number; + @ApiProperty({ description: '開始位置' }) + @IsInt() + @Min(0) + offset: number; +} + +export class Partner { + @ApiProperty({ description: '会社名' }) + name: string; + @ApiProperty({ description: '階層' }) + tier: number; + @ApiProperty({ description: 'アカウントID' }) + accountId: number; + @ApiProperty({ description: '国' }) + country: string; + @ApiProperty({ description: 'プライマリ管理者' }) + primaryAdmin: string; + @ApiProperty({ description: 'プライマリ管理者メールアドレス' }) + email: string; + @ApiProperty({ description: '代行操作許可' }) + dealerManagement: boolean; +} + +export class GetPartnersResponse { + @ApiProperty({ description: '合計件数' }) + total: number; + @ApiProperty({ type: [Partner] }) + partners: Partner[]; +}