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,