Merged PR 384: API IF実装

## 概要
[Task2568: API IF実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2568)

- worktype更新APIのIFを実装し、OpenAPI定義を更新しました。

## レビューポイント
- パスは適切か
- パラメータの制約は適切か

## UIの変更
- なし
## 動作確認状況
- ローカルで確認
This commit is contained in:
makabe.t 2023-09-05 08:09:41 +00:00
parent b9a2d9b6b4
commit bde1ff60a9
3 changed files with 146 additions and 0 deletions

View File

@ -838,6 +838,69 @@
"security": [{ "bearer": [] }]
}
},
"/accounts/worktypes/{id}": {
"post": {
"operationId": "updateWorktype",
"summary": "",
"parameters": [
{
"name": "id",
"required": true,
"in": "path",
"description": "Worktypeの内部ID",
"schema": { "type": "number" }
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateWorktypesRequest"
}
}
}
},
"responses": {
"200": {
"description": "成功時のレスポンス",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateWorktypeResponse"
}
}
}
},
"400": {
"description": "WorktypeIDが重複 / WorktypeIDが空",
"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/partners": {
"get": {
"operationId": "getPartners",
@ -2825,6 +2888,19 @@
"required": ["worktypeId"]
},
"CreateWorktypeResponse": { "type": "object", "properties": {} },
"UpdateWorktypesRequest": {
"type": "object",
"properties": {
"worktypeId": {
"type": "string",
"minLength": 1,
"description": "WorktypeID"
},
"description": { "type": "string", "description": "Worktypeの説明" }
},
"required": ["worktypeId"]
},
"UpdateWorktypeResponse": { "type": "object", "properties": {} },
"Partner": {
"type": "object",
"properties": {

View File

@ -48,6 +48,9 @@ import {
CreateWorktypesRequest,
GetPartnersRequest,
GetPartnersResponse,
UpdateWorktypeRequestParam,
UpdateWorktypeResponse,
UpdateWorktypesRequest,
} from './types/types';
import { USER_ROLES, ADMIN_ROLES, TIERS } from '../../constants';
import { AuthGuard } from '../../common/guards/auth/authguards';
@ -719,6 +722,51 @@ export class AccountsController {
return {};
}
@Post('/worktypes/:id')
@ApiResponse({
status: HttpStatus.OK,
type: UpdateWorktypeResponse,
description: '成功時のレスポンス',
})
@ApiResponse({
status: HttpStatus.BAD_REQUEST,
description: 'WorktypeIDが重複 / WorktypeIDが空',
type: ErrorResponse,
})
@ApiResponse({
status: HttpStatus.UNAUTHORIZED,
description: '認証エラー',
type: ErrorResponse,
})
@ApiResponse({
status: HttpStatus.INTERNAL_SERVER_ERROR,
description: '想定外のサーバーエラー',
type: ErrorResponse,
})
@ApiOperation({ operationId: 'updateWorktype' })
@ApiBearerAuth()
@UseGuards(AuthGuard)
@UseGuards(RoleGuard.requireds({ roles: [ADMIN_ROLES.ADMIN] }))
async updateWorktype(
@Req() req: Request,
@Param() param: UpdateWorktypeRequestParam,
@Body() body: UpdateWorktypesRequest,
): Promise<UpdateWorktypeResponse> {
const { worktypeId, description } = body;
const { id } = param;
const token = retrieveAuthorizationToken(req);
const { userId } = jwt.decode(token, { json: true }) as AccessToken;
const context = makeContext(userId);
console.log('worktypeId: ', worktypeId);
console.log('description: ', description);
console.log('id: ', id);
console.log(context.trackingId);
return {};
}
@Get('/partners')
@ApiResponse({
status: HttpStatus.OK,

View File

@ -362,6 +362,28 @@ export class CreateWorktypesRequest {
export class CreateWorktypeResponse {}
export class UpdateWorktypesRequest {
@ApiProperty({ minLength: 1, description: 'WorktypeID' })
@MinLength(1)
@MaxLength(255)
@IsWorktypeId()
worktypeId: string;
@ApiProperty({ description: 'Worktypeの説明', required: false })
@MaxLength(255)
@IsOptional()
description?: string;
}
export class UpdateWorktypeResponse {}
export class UpdateWorktypeRequestParam {
@ApiProperty({ description: 'Worktypeの内部ID' })
@Type(() => Number)
@IsInt()
@Min(0)
id: number;
}
export class GetPartnersRequest {
@ApiProperty({ description: '取得件数' })
@IsInt()