From 9f2f1631416003518539ca896a67aad59cde9601 Mon Sep 17 00:00:00 2001 From: "oura.a" Date: Fri, 25 Aug 2023 05:19:34 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20359:=20API=20IF=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2482: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2482) ライセンス注文キャンセルAPIのIFを実装しました。 ※同ファイル内に未使用のGetAllocatableLicensesRequestのインポートが残っていたので、ついでに削除しています。本APIとは無関係です。 ## レビューポイント なし ## UIの変更 なし ## 動作確認状況 Swagger UIで確認済み ## 補足 なし --- dictation_server/src/api/odms/openapi.json | 57 +++++++++++++++++++ .../features/licenses/licenses.controller.ts | 53 ++++++++++++++++- .../src/features/licenses/types/types.ts | 8 +++ 3 files changed, 117 insertions(+), 1 deletion(-) diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 0b3195b..49857c8 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -2020,6 +2020,57 @@ "security": [{ "bearer": [] }] } }, + "/licenses/orders/cancel": { + "post": { + "operationId": "cancelOrder", + "summary": "", + "parameters": [], + "requestBody": { + "required": true, + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/CancelOrderRequest" } + } + } + }, + "responses": { + "200": { + "description": "成功時のレスポンス", + "content": { + "application/json": { + "schema": { "$ref": "#/components/schemas/CancelOrderResponse" } + } + } + }, + "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": ["licenses"], + "security": [{ "bearer": [] }] + } + }, "/notification/register": { "post": { "operationId": "register", @@ -2929,6 +2980,12 @@ }, "required": ["allocatableLicenses"] }, + "CancelOrderRequest": { + "type": "object", + "properties": { "poNumber": { "type": "string" } }, + "required": ["poNumber"] + }, + "CancelOrderResponse": { "type": "object", "properties": {} }, "RegisterRequest": { "type": "object", "properties": { diff --git a/dictation_server/src/features/licenses/licenses.controller.ts b/dictation_server/src/features/licenses/licenses.controller.ts index f599211..534bc81 100644 --- a/dictation_server/src/features/licenses/licenses.controller.ts +++ b/dictation_server/src/features/licenses/licenses.controller.ts @@ -23,7 +23,8 @@ import { ActivateCardLicensesResponse, ActivateCardLicensesRequest, GetAllocatableLicensesResponse, - GetAllocatableLicensesRequest, + CancelOrderRequest, + CancelOrderResponse, } from './types/types'; import { Request } from 'express'; import { retrieveAuthorizationToken } from '../../common/http/helper'; @@ -216,4 +217,54 @@ export class LicensesController { return allocatableLicenses; } + + @ApiResponse({ + status: HttpStatus.OK, + type: CancelOrderResponse, + 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: 'cancelOrder', + description: 'ライセンス注文をキャンセルします', + }) + @ApiBearerAuth() + @UseGuards(AuthGuard) + @UseGuards( + RoleGuard.requireds({ + roles: [ADMIN_ROLES.ADMIN], + tiers: [TIERS.TIER2, TIERS.TIER3, TIERS.TIER4, TIERS.TIER5], + }), + ) + @Post('/orders/cancel') + async cancelOrder( + @Req() req: Request, + @Body() body: CancelOrderRequest, + ): Promise { + const token = retrieveAuthorizationToken(req); + const payload = jwt.decode(token, { json: true }) as AccessToken; + + const context = makeContext(payload.userId); + + // 注文キャンセル処理(仮) + // await this.licensesService.cancelOrder( + // context, + // body.poNumber, + // ); + return {}; + } } diff --git a/dictation_server/src/features/licenses/types/types.ts b/dictation_server/src/features/licenses/types/types.ts index e0fce77..a75885f 100644 --- a/dictation_server/src/features/licenses/types/types.ts +++ b/dictation_server/src/features/licenses/types/types.ts @@ -55,6 +55,14 @@ export class GetAllocatableLicensesResponse { allocatableLicenses: AllocatableLicenseInfo[]; } +export class CancelOrderRequest { + @ApiProperty() + @Matches(/^[A-Z0-9]+$/) + poNumber: string; +} + +export class CancelOrderResponse {} + // ライセンス算出用に、その日の始まりの時刻(0:00:00.000)の日付を取得する export class DateWithZeroTime extends Date { constructor(...args: any[]) {