From c6f63c962c6969f8484dc5187f33e31a4eb43387 Mon Sep 17 00:00:00 2001 From: Kentaro Fukunaga Date: Sun, 23 Jul 2023 23:41:09 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20258:=20getRelations=E3=82=92?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E9=80=A3=E6=90=BA=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E7=94=A8=E3=81=AB=E5=86=85=E9=83=A8=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task2257: 実装](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2257) - AuthorIDは本物の値を返却し、それ以外はダミーの固定値を返却する実装を入れました。 - npm run formatをかけました ## レビューポイント - 気になる点ないか:To真壁くん - npm run formatの結果共有:Toガンさん(パートナー追加PBIのところで出ていたので) ## 動作確認状況 - ローカルでPostmanを使用し、Authorのときとそうでないとき両方確認 --- .../accounts/accounts.service.spec.ts | 25 +-- .../accounts/test/accounts.service.mock.ts | 6 +- .../src/features/accounts/types/types.ts | 2 +- .../src/features/users/users.controller.ts | 26 +--- .../src/features/users/users.service.ts | 145 +++++++++++++++++- 5 files changed, 170 insertions(+), 34 deletions(-) diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index f3e5dc0..79d839e 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -217,11 +217,11 @@ describe('AccountsService', () => { ); }); it('パートナーを追加できる', async () => { - const companyName = "TEST_COMPANY"; - const country = "US"; - const email = "xxx@example.com"; - const adminName = "ADMIN"; - const userId = "100"; + const companyName = 'TEST_COMPANY'; + const country = 'US'; + const email = 'xxx@example.com'; + const adminName = 'ADMIN'; + const userId = '100'; const tier = 3; const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue(); const userGroupsRepositoryMockValue = @@ -231,7 +231,7 @@ describe('AccountsService', () => { makeDefaultAccountsRepositoryMockValue(); const configMockValue = makeDefaultConfigValue(); const sendGridMockValue = makeDefaultSendGridlValue(); - + const service = await makeAccountsServiceMock( accountsRepositoryMockValue, usersRepositoryMockValue, @@ -240,9 +240,16 @@ describe('AccountsService', () => { configMockValue, sendGridMockValue, ); - expect(await service.createPartnerAccount(companyName, country,email,adminName,userId,tier +1)).toEqual( - undefined, - ); + expect( + await service.createPartnerAccount( + companyName, + country, + email, + adminName, + userId, + tier + 1, + ), + ).toEqual(undefined); }); it('アカウントの追加に失敗した場合、エラーとなる', async () => { const companyName = 'TEST_COMPANY'; diff --git a/dictation_server/src/features/accounts/test/accounts.service.mock.ts b/dictation_server/src/features/accounts/test/accounts.service.mock.ts index b543f93..e9e65c5 100644 --- a/dictation_server/src/features/accounts/test/accounts.service.mock.ts +++ b/dictation_server/src/features/accounts/test/accounts.service.mock.ts @@ -169,7 +169,11 @@ export const makeConfigMock = (value: ConfigMockValue) => { }; }; export const makeSendGridServiceMock = (value: SendGridMockValue) => { - const { createMailContentFromEmailConfirm,createMailContentFromEmailConfirmForNormalUser, sendMail } = value; + const { + createMailContentFromEmailConfirm, + createMailContentFromEmailConfirmForNormalUser, + sendMail, + } = value; return { createMailContentFromEmailConfirm: createMailContentFromEmailConfirm instanceof Error diff --git a/dictation_server/src/features/accounts/types/types.ts b/dictation_server/src/features/accounts/types/types.ts index 3d12f23..a7a2e71 100644 --- a/dictation_server/src/features/accounts/types/types.ts +++ b/dictation_server/src/features/accounts/types/types.ts @@ -185,4 +185,4 @@ export class GetPartnerLicensesResponse { ownPartnerLicense: PartnerLicenseInfo; @ApiProperty({ type: [PartnerLicenseInfo] }) childrenPartnerLicenses: PartnerLicenseInfo[]; -} \ No newline at end of file +} diff --git a/dictation_server/src/features/users/users.controller.ts b/dictation_server/src/features/users/users.controller.ts index 880f9c2..ffb6bcd 100644 --- a/dictation_server/src/features/users/users.controller.ts +++ b/dictation_server/src/features/users/users.controller.ts @@ -202,30 +202,12 @@ export class UsersController { description: 'ログインしているユーザーに関連する各種情報を取得します', }) @ApiBearerAuth() + @UseGuards(AuthGuard) @Get('relations') async getRelations(@Req() req: Request): Promise { - console.log(req.header('Authorization')); - return { - authorId: 'AUTHOR', - authorIdList: ['AUTHOR', 'AUTHOR1'], - workTypeList: [ - { - workTypeId: '1', - optionItemList: [ - { - label: '1', - initialValueType: 0, - defaultValue: 'default', - }, - ], - }, - ], - isEncrypted: true, - encryptionPassword: '', - activeWorktype: '', - audioFormat: 'DS2', - prompt: true, - }; + const token = retrieveAuthorizationToken(req); + const { userId } = jwt.decode(token, { json: true }) as AccessToken; + return await this.usersService.getRelations(userId); } @ApiResponse({ diff --git a/dictation_server/src/features/users/users.service.ts b/dictation_server/src/features/users/users.service.ts index 7176bd9..c973d6d 100644 --- a/dictation_server/src/features/users/users.service.ts +++ b/dictation_server/src/features/users/users.service.ts @@ -20,7 +20,7 @@ import { SendGridService } from '../../gateways/sendgrid/sendgrid.service'; import { SortCriteriaRepositoryService } from '../../repositories/sort_criteria/sort_criteria.repository.service'; import { User as EntityUser } from '../../repositories/users/entity/user.entity'; import { UsersRepositoryService } from '../../repositories/users/users.repository.service'; -import { User } from './types/types'; +import { GetRelationsResponse, User } from './types/types'; import { EmailAlreadyVerifiedError } from '../../repositories/users/errors/types'; @Injectable() @@ -426,4 +426,147 @@ export class UsersService { this.logger.log(`[OUT] ${this.getSortCriteria.name}`); } } + + /** + * 指定したユーザーの文字起こし業務に関連する情報を取得します + * @param userId + * @returns relations + */ + async getRelations(userId: string): Promise { + this.logger.log(`[IN] ${this.getRelations.name}`); + try { + const user = await this.usersRepository.findUserByExternalId(userId); + + // TODO: PBI2105 本実装時に修正すること + return { + authorId: user.author_id, + authorIdList: [user.author_id, 'XXX'], + isEncrypted: false, + audioFormat: 'DS2', + prompt: false, + workTypeList: [ + { + workTypeId: 'workType1', + optionItemList: [ + { + label: 'optionItem11', + initialValueType: 2, + defaultValue: 'default11', + }, + { + label: 'optionItem12', + initialValueType: 2, + defaultValue: 'default12', + }, + { + label: 'optionItem13', + initialValueType: 2, + defaultValue: 'default13', + }, + { + label: 'optionItem14', + initialValueType: 2, + defaultValue: 'default14', + }, + { + label: 'optionItem15', + initialValueType: 2, + defaultValue: 'default15', + }, + { + label: 'optionItem16', + initialValueType: 2, + defaultValue: 'default16', + }, + { + label: 'optionItem17', + initialValueType: 2, + defaultValue: 'default17', + }, + { + label: 'optionItem18', + initialValueType: 2, + defaultValue: 'default18', + }, + { + label: 'optionItem19', + initialValueType: 1, + defaultValue: '', + }, + { + label: 'optionItem110', + initialValueType: 3, + defaultValue: '', + }, + ], + }, + { + workTypeId: 'workType2', + optionItemList: [ + { + label: 'optionItem21', + initialValueType: 2, + defaultValue: 'default21', + }, + { + label: 'optionItem22', + initialValueType: 2, + defaultValue: 'default22', + }, + { + label: 'optionItem23', + initialValueType: 2, + defaultValue: 'defaul23', + }, + { + label: 'optionItem24', + initialValueType: 2, + defaultValue: 'default24', + }, + { + label: 'optionItem25', + initialValueType: 2, + defaultValue: 'default25', + }, + { + label: 'optionItem26', + initialValueType: 2, + defaultValue: 'default26', + }, + { + label: 'optionItem27', + initialValueType: 2, + defaultValue: 'default27', + }, + { + label: 'optionItem28', + initialValueType: 2, + defaultValue: 'default28', + }, + { + label: 'optionItem29', + initialValueType: 1, + defaultValue: '', + }, + { + label: 'optionItem210', + initialValueType: 3, + defaultValue: '', + }, + ], + }, + ], + activeWorktype: 'workType1', + }; + } catch (e) { + this.logger.error(`error=${e}`); + + throw new HttpException( + makeErrorResponse('E009999'), + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } finally { + this.logger.log(`[OUT] ${this.getRelations.name}`); + } + } }