From f1684a56168919169d559f67ebb76c99afa354f9 Mon Sep 17 00:00:00 2001 From: "makabe.t" Date: Wed, 2 Aug 2023 07:47:31 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20297:=20API=20IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2319: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2319) - ユーザー編集APIのI/Fを実装しました。 - openapi.json生成 ## レビューポイント - プロパティは適切か ## UIの変更 - なし ## 動作確認状況 - ローカルで確認 Swagger --- dictation_server/src/api/odms/openapi.json | 82 ++++++++++++++++--- .../src/features/users/types/types.ts | 32 ++++++++ .../src/features/users/users.controller.ts | 42 ++++++++++ 3 files changed, 146 insertions(+), 10 deletions(-) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 5562e3a..9e50827 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -749,6 +749,60 @@ "security": [{ "bearer": [] }] } }, + "/users/update": { + "post": { + "operationId": "updateUser", + "summary": "", + "description": "ユーザーの情報を更新します", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/PostUpdateUserRequest" } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/PostUpdateUserResponse" + } + } + } + }, + "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": ["users"], + "security": [{ "bearer": [] }] + } + }, "/files/audio/upload-finished": { "post": { "operationId": "uploadFinished", @@ -1976,16 +2030,8 @@ "LicenseOrder": { "type": "object", "properties": { - "orderDate": { - "format": "date-time", - "type": "string", - "description": "注文日付" - }, - "issueDate": { - "format": "date-time", - "type": "string", - "description": "発行日付" - }, + "orderDate": { "type": "string", "description": "注文日付" }, + "issueDate": { "type": "string", "description": "発行日付" }, "numberOfOrder": { "type": "number", "description": "注文数" }, "poNumber": { "type": "string", "description": "POナンバー" }, "status": { "type": "string", "description": "注文状態" } @@ -2191,6 +2237,22 @@ }, "required": ["direction", "paramName"] }, + "PostUpdateUserRequest": { + "type": "object", + "properties": { + "id": { "type": "number" }, + "role": { "type": "string", "description": "none/author/typist" }, + "authorId": { "type": "string" }, + "autoRenew": { "type": "boolean" }, + "licenseAlart": { "type": "boolean" }, + "notification": { "type": "boolean" }, + "encryption": { "type": "boolean" }, + "encryptionPassword": { "type": "string" }, + "prompt": { "type": "boolean" } + }, + "required": ["id", "role", "autoRenew", "licenseAlart", "notification"] + }, + "PostUpdateUserResponse": { "type": "object", "properties": {} }, "AudioOptionItem": { "type": "object", "properties": { diff --git a/dictation_server/src/features/users/types/types.ts b/dictation_server/src/features/users/types/types.ts index c789013..308cc26 100644 --- a/dictation_server/src/features/users/types/types.ts +++ b/dictation_server/src/features/users/types/types.ts @@ -184,3 +184,35 @@ export class GetSortCriteriaResponse { }) paramName: string; } + +export class PostUpdateUserRequest { + @ApiProperty() + id: number; + + @ApiProperty({ description: 'none/author/typist' }) + @IsIn([USER_ROLES.NONE, USER_ROLES.AUTHOR, USER_ROLES.TYPIST]) + role: string; + + @ApiProperty({ required: false }) + authorId?: string | undefined; + + @ApiProperty() + autoRenew: boolean; + + @ApiProperty() + licenseAlart: boolean; + + @ApiProperty() + notification: boolean; + + @ApiProperty({ required: false }) + encryption?: boolean | undefined; + + @ApiProperty({ required: false }) + encryptionPassword?: string | undefined; + + @ApiProperty({ required: false }) + prompt?: boolean | undefined; +} + +export class PostUpdateUserResponse {} diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index c3a1474..527e1f8 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -31,6 +31,8 @@ import { PostSortCriteriaResponse, GetSortCriteriaRequest, GetSortCriteriaResponse, + PostUpdateUserRequest, + PostUpdateUserResponse, } from './types/types'; import { UsersService } from './users.service'; import jwt from 'jsonwebtoken'; @@ -300,4 +302,44 @@ export class UsersController { ); return { direction, paramName }; } + + @ApiResponse({ + status: HttpStatus.OK, + type: PostUpdateUserResponse, + 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: 'updateUser', + description: 'ユーザーの情報を更新します', + }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] })) + @Post('update') + async updateUser( + @Body() body: PostUpdateUserRequest, + @Req() req: Request, + ): Promise { + const accessToken = retrieveAuthorizationToken(req); + const decodedToken = jwt.decode(accessToken, { json: true }) as AccessToken; + + console.log(body); + console.log(decodedToken); + return {}; + } }