Merged PR 520: API IF作成
## 概要 [Task2919: API IF作成](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2919) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) 新規のためなし ## レビューポイント メソッド名がふさわしいか ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
565db8c8b7
commit
4b812fc0b3
@ -1874,6 +1874,42 @@
|
||||
"tags": ["users"]
|
||||
}
|
||||
},
|
||||
"/users/me": {
|
||||
"get": {
|
||||
"operationId": "getMyUser",
|
||||
"summary": "",
|
||||
"description": "ログインしているユーザーの情報を取得します",
|
||||
"parameters": [],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "成功時のレスポンス",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": { "$ref": "#/components/schemas/GetMyUserResponse" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "該当ユーザーがDBに存在しない場合",
|
||||
"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",
|
||||
@ -4141,6 +4177,13 @@
|
||||
"required": ["idToken", "acceptedEULAVersion"]
|
||||
},
|
||||
"UpdateAcceptedVersionResponse": { "type": "object", "properties": {} },
|
||||
"GetMyUserResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"userName": { "type": "string", "description": "ユーザー名" }
|
||||
},
|
||||
"required": ["userName"]
|
||||
},
|
||||
"AudioOptionItem": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@ -10,6 +10,7 @@ import {
|
||||
IsPasswordvalid,
|
||||
} from '../../../common/validators/encryptionPassword.validator';
|
||||
import { IsRoleAuthorDataValid } from '../../../common/validators/roleAuthor.validator';
|
||||
import { Aadb2cUser } from '../../../common/token';
|
||||
|
||||
export class ConfirmRequest {
|
||||
@ApiProperty()
|
||||
@ -266,3 +267,8 @@ export class UpdateAcceptedVersionRequest {
|
||||
}
|
||||
|
||||
export class UpdateAcceptedVersionResponse {}
|
||||
|
||||
export class GetMyUserResponse {
|
||||
@ApiProperty({ description: 'ユーザー名' })
|
||||
userName: string;
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ import {
|
||||
DeallocateLicenseRequest,
|
||||
UpdateAcceptedVersionRequest,
|
||||
UpdateAcceptedVersionResponse,
|
||||
GetMyUserResponse,
|
||||
} from './types/types';
|
||||
import { UsersService } from './users.service';
|
||||
import { AuthService } from '../auth/auth.service';
|
||||
@ -53,6 +54,7 @@ import { RoleGuard } from '../../common/guards/role/roleguards';
|
||||
import { makeContext } from '../../common/log';
|
||||
import { UserRoles } from '../../common/types/role';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { userInfo } from 'os';
|
||||
|
||||
@ApiTags('users')
|
||||
@Controller('users')
|
||||
@ -621,4 +623,47 @@ export class UsersController {
|
||||
);
|
||||
return {};
|
||||
}
|
||||
@ApiResponse({
|
||||
status: HttpStatus.OK,
|
||||
type: GetMyUserResponse,
|
||||
description: '成功時のレスポンス',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: HttpStatus.BAD_REQUEST,
|
||||
description: '該当ユーザーがDBに存在しない場合',
|
||||
type: ErrorResponse,
|
||||
})
|
||||
@ApiResponse({
|
||||
status: HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
description: '想定外のサーバーエラー',
|
||||
type: ErrorResponse,
|
||||
})
|
||||
@ApiOperation({
|
||||
operationId: 'getMyUser',
|
||||
description: 'ログインしているユーザーの情報を取得します',
|
||||
})
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(AuthGuard)
|
||||
@Get('me')
|
||||
async getMyUser(@Req() req: Request): Promise<GetMyUserResponse> {
|
||||
const accessToken = retrieveAuthorizationToken(req) as string;
|
||||
if (!accessToken) {
|
||||
throw new HttpException(
|
||||
makeErrorResponse('E000107'),
|
||||
HttpStatus.UNAUTHORIZED,
|
||||
);
|
||||
}
|
||||
const decodedAccessToken = jwt.decode(accessToken, { json: true });
|
||||
if (!decodedAccessToken) {
|
||||
throw new HttpException(
|
||||
makeErrorResponse('E000101'),
|
||||
HttpStatus.UNAUTHORIZED,
|
||||
);
|
||||
}
|
||||
const { userId } = decodedAccessToken as AccessToken;
|
||||
const context = makeContext(userId);
|
||||
const userName = 'TEST';
|
||||
//const userName = await this.usersService.getUserName(context, userId);
|
||||
return { userName };
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user