From b88c0d9b96bed4eb1bf515c67cfc51127ba24847 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Fri, 19 Apr 2024 04:47:32 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20877:=20=E3=83=87=E3=82=A3?= =?UTF-8?q?=E3=83=BC=E3=83=A9=E3=83=BC=E5=8F=96=E5=BE=97API=E3=81=AE?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task4104: ディーラー取得APIの修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4104) - メールの文面を各言語版に置き換えました。 - 環境変数に設定されたアカウントIDのDealerはResponseに含めないように修正 ## レビューポイント - 環境変数からインスタンス変数に代入するときの処理に問題はあるか - 環境変数のフォーマットはこれで良いか - もっとよいやり方があれば指摘いただきたいです - テストケースに不足はないか ## UIの変更 - なし ## クエリの変更 - なし ## 動作確認状況 - ローカルで確認 - 行った修正がデグレを発生させていないことを確認できるか - ほかのテストに影響が出ていない --- dictation_server/.env.local.example | 3 +- dictation_server/.env.test | 3 +- .../src/common/validators/env.validator.ts | 4 ++ .../accounts/accounts.service.spec.ts | 29 ++++++++++++ .../src/features/accounts/accounts.service.ts | 46 +++++++++++++++++-- 5 files changed, 80 insertions(+), 5 deletions(-) diff --git a/dictation_server/.env.local.example b/dictation_server/.env.local.example index 8c03436..5aaecca 100644 --- a/dictation_server/.env.local.example +++ b/dictation_server/.env.local.example @@ -33,4 +33,5 @@ EMAIL_CONFIRM_LIFETIME=86400 REDIS_HOST=redis-cache REDIS_PORT=6379 REDIS_PASSWORD=omdsredispass -ADB2C_CACHE_TTL=86400 \ No newline at end of file +ADB2C_CACHE_TTL=86400 +DEALER_ACCOUNT_ID_HIDDEN_LIST=1,2,3,4 \ No newline at end of file diff --git a/dictation_server/.env.test b/dictation_server/.env.test index a2748df..ca88821 100644 --- a/dictation_server/.env.test +++ b/dictation_server/.env.test @@ -34,4 +34,5 @@ REDIS_HOST=redis-cache REDIS_PORT=6379 REDIS_PASSWORD=omdsredispass ADB2C_CACHE_TTL=86400 -TEMPLATE_ROOT=dist \ No newline at end of file +TEMPLATE_ROOT=dist +DEALER_ACCOUNT_ID_HIDDEN_LIST=50,99 \ No newline at end of file diff --git a/dictation_server/src/common/validators/env.validator.ts b/dictation_server/src/common/validators/env.validator.ts index 8ce706f..8ce1547 100644 --- a/dictation_server/src/common/validators/env.validator.ts +++ b/dictation_server/src/common/validators/env.validator.ts @@ -32,6 +32,10 @@ export class EnvValidator { @IsString() DB_PASSWORD: string; + @IsOptional() + @IsString() + DEALER_ACCOUNT_ID_HIDDEN_LIST: string; + // .env.local @IsOptional() @IsString() diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index 29c5899..d5e0575 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -2645,6 +2645,35 @@ describe('getDealers', () => { ], }); }); + + it('非表示指定されたDealer以外のDealerを取得できる', async () => { + if (!source) fail(); + const module = await makeTestingModule(source); + if (!module) fail(); + // 100件のDealerを作成し、country,id,company_nameを取得する + const dealers: { country: string; id: number; name: string }[] = []; + for (let i = 0; i < 100; i++) { + const { id, company_name, country } = ( + await makeTestAccount(source, { + parent_account_id: i, + tier: TIERS.TIER4, + country: 'JP', + company_name: `DEALER_${i}`, + }) + ).account; + dealers.push({ id, name: company_name, country }); + } + const service = module.get(AccountsService); + const context = makeContext(`uuidv4`, 'requestId'); + const result = await service.getDealers(context); + // idが50と99のDealerを非表示にする + + expect(result.dealers.length).toBe(98); + expect(result).toEqual({ + dealers: dealers.filter((dealer) => dealer.id !== 50 && dealer.id !== 99), + }); + }); + it('0件でもDealerを取得できる', async () => { if (!source) fail(); const module = await makeTestingModule(source); diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index 8b6e271..688981b 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -72,9 +72,13 @@ import { WorktypeIdNotFoundError, } from '../../repositories/worktypes/errors/types'; import { getUserNameAndMailAddress } from '../../gateways/adb2c/utils/utils'; +import { ConfigService } from '@nestjs/config'; @Injectable() export class AccountsService { + // プロダクト バックログ項目 4077: [保守]本番環境動作確認用のDealerアカウントを表示しないようにする の対応 + private readonly dealerAccountIdHiddenList: number[] = []; + private readonly logger = new Logger(AccountsService.name); constructor( private readonly accountRepository: AccountsRepositoryService, private readonly licensesRepository: LicensesRepositoryService, @@ -84,8 +88,27 @@ export class AccountsService { private readonly adB2cService: AdB2cService, private readonly sendgridService: SendGridService, private readonly blobStorageService: BlobstorageService, - ) {} - private readonly logger = new Logger(AccountsService.name); + private readonly configService: ConfigService, + ) { + const dealerAccountIdList = this.configService.get( + 'DEALER_ACCOUNT_ID_HIDDEN_LIST', + ); + // ディーラーアカウントIDリストを数値配列に変換する + // 変換できない場合はエラーをスローする + // 存在しない場合や空文字列の場合は空の配列を返す + if (dealerAccountIdList) { + this.dealerAccountIdHiddenList = dealerAccountIdList + .split(',') + .map((x) => { + const id = parseInt(x, 10); + if (isNaN(id)) { + throw new Error('DEALER_ACCOUNT_ID_HIDDEN_LIST is invalid'); + } + return id; + }); + } + } + /** * 第五階層用のライセンス情報を取得する * @param accountId @@ -1174,9 +1197,26 @@ export class AccountsService { const dealerAccounts = await this.accountRepository.findDealerAccounts( context, ); + // プロダクト バックログ項目 4077: [保守]本番環境動作確認用のDealerアカウントを表示しないようにする の対応 + // this.dealerAccountIdHiddenListに含まれるアカウント(動作確認用のアカウント)を除外する。 + // 除外したアカウントをlogに出力する + const filteredDealerAccounts = dealerAccounts.filter((dealerAccount) => { + const isHidden = this.dealerAccountIdHiddenList.includes( + dealerAccount.id, + ); + if (isHidden) { + this.logger.log( + `[${context.getTrackingId()}] hidden dealer account: ${ + dealerAccount.id + }`, + ); + } + return !isHidden; + }); + // レスポンス用の型に変換 const dealers: GetDealersResponse = { - dealers: dealerAccounts.map((dealerAccount): Dealer => { + dealers: filteredDealerAccounts.map((dealerAccount): Dealer => { return { id: dealerAccount.id, name: dealerAccount.company_name,