From ba371ac4c0d8828337ee61c5312874f4962b0293 Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Thu, 24 Aug 2023 00:08:22 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20345:=20API=20IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2438: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2438) - TypistGroup追加APIを実装しました。 - openapi.jsonを更新 ## レビューポイント - パラメータの制限は適切か - パスは適切か ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 --- dictation_server/src/api/odms/openapi.json | 71 +++++++++++++++++++ .../features/accounts/accounts.controller.ts | 42 +++++++++++ .../src/features/accounts/types/types.ts | 23 +++++- 3 files changed, 135 insertions(+), 1 deletion(-) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 2c10dd6..0b3195b 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -298,6 +298,60 @@ }, "tags": ["accounts"], "security": [{ "bearer": [] }] + }, + "post": { + "operationId": "createTypistGroup", + "summary": "", + "description": "ログインしているユーザーのアカウント配下にタイピストグループを追加します", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateTypistGroupRequest" + } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateTypistGroupResponse" + } + } + } + }, + "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": [] }] } }, "/accounts/partner": { @@ -2177,6 +2231,23 @@ }, "required": ["typistGroups"] }, + "CreateTypistGroupRequest": { + "type": "object", + "properties": { + "typistGroupName": { + "type": "string", + "minLength": 1, + "maxLength": 50 + }, + "typistIds": { + "minItems": 1, + "type": "array", + "items": { "type": "string" } + } + }, + "required": ["typistGroupName", "typistIds"] + }, + "CreateTypistGroupResponse": { "type": "object", "properties": {} }, "CreatePartnerAccountRequest": { "type": "object", "properties": { diff --git a/dictation_server/src/features/accounts/accounts.controller.ts b/dictation_server/src/features/accounts/accounts.controller.ts index 05240da..1fec4f0 100644 --- a/dictation_server/src/features/accounts/accounts.controller.ts +++ b/dictation_server/src/features/accounts/accounts.controller.ts @@ -33,6 +33,8 @@ import { IssueLicenseRequest, IssueLicenseResponse, GetDealersResponse, + CreateTypistGroupResponse, + CreateTypistGroupRequest, } from './types/types'; import { USER_ROLES, ADMIN_ROLES, TIERS } from '../../constants'; import { AuthGuard } from '../../common/guards/auth/authguards'; @@ -243,6 +245,46 @@ export class AccountsController { return { typistGroups }; } + @ApiResponse({ + status: HttpStatus.OK, + type: CreateTypistGroupResponse, + 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: 'createTypistGroup', + description: + 'ログインしているユーザーのアカウント配下にタイピストグループを追加します', + }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] })) + @Post('typist-groups') + async createTypistGroup( + @Req() req: Request, + @Body() body: CreateTypistGroupRequest, + ): Promise { + // アクセストークン取得 + const accessToken = retrieveAuthorizationToken(req); + const payload = jwt.decode(accessToken, { json: true }) as AccessToken; + + return {}; + } + @Post('partner') @ApiResponse({ status: HttpStatus.OK, diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index 0a0deff..fb87e37 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -1,5 +1,14 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsEmail, IsInt, IsOptional, Matches, Min } from 'class-validator'; +import { + IsEmail, + IsInt, + IsOptional, + Matches, + MaxLength, + Min, + ArrayMinSize, + MinLength, +} from 'class-validator'; import { IsAdminPasswordvalid } from '../../../common/validators/admin.validator'; export class CreateAccountRequest { @@ -122,6 +131,18 @@ export class GetTypistGroupsResponse { typistGroups: TypistGroup[]; } +export class CreateTypistGroupRequest { + @ApiProperty({ minLength: 1, maxLength: 50 }) + @MinLength(1) + @MaxLength(50) + typistGroupName: string; + @ApiProperty({ minItems: 1 }) + @ArrayMinSize(1) + typistIds: number[]; +} + +export class CreateTypistGroupResponse {} + export class CreatePartnerAccountRequest { @ApiProperty() companyName: string;