diff --git a/dictation_server/src/api/odms/openapi.json b/dictation_server/src/api/odms/openapi.json index 993efb4..76bf8c9 100644 --- a/dictation_server/src/api/odms/openapi.json +++ b/dictation_server/src/api/odms/openapi.json @@ -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": { diff --git a/dictation_server/src/features/users/types/types.ts b/dictation_server/src/features/users/types/types.ts index 991ec09..b75b6b6 100644 --- a/dictation_server/src/features/users/types/types.ts +++ b/dictation_server/src/features/users/types/types.ts @@ -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; +} diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index ee6175a..c9d6a56 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -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 { + 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 }; + } }