Merged PR 877: ディーラー取得APIの修正
## 概要 [Task4104: ディーラー取得APIの修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4104) - メールの文面を各言語版に置き換えました。 - 環境変数に設定されたアカウントIDのDealerはResponseに含めないように修正 ## レビューポイント - 環境変数からインスタンス変数に代入するときの処理に問題はあるか - 環境変数のフォーマットはこれで良いか - もっとよいやり方があれば指摘いただきたいです - テストケースに不足はないか ## UIの変更 - なし ## クエリの変更 - なし ## 動作確認状況 - ローカルで確認 - 行った修正がデグレを発生させていないことを確認できるか - ほかのテストに影響が出ていない
This commit is contained in:
parent
a7b18d8151
commit
b88c0d9b96
@ -34,3 +34,4 @@ REDIS_HOST=redis-cache
|
|||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
REDIS_PASSWORD=omdsredispass
|
REDIS_PASSWORD=omdsredispass
|
||||||
ADB2C_CACHE_TTL=86400
|
ADB2C_CACHE_TTL=86400
|
||||||
|
DEALER_ACCOUNT_ID_HIDDEN_LIST=1,2,3,4
|
||||||
@ -35,3 +35,4 @@ REDIS_PORT=6379
|
|||||||
REDIS_PASSWORD=omdsredispass
|
REDIS_PASSWORD=omdsredispass
|
||||||
ADB2C_CACHE_TTL=86400
|
ADB2C_CACHE_TTL=86400
|
||||||
TEMPLATE_ROOT=dist
|
TEMPLATE_ROOT=dist
|
||||||
|
DEALER_ACCOUNT_ID_HIDDEN_LIST=50,99
|
||||||
@ -32,6 +32,10 @@ export class EnvValidator {
|
|||||||
@IsString()
|
@IsString()
|
||||||
DB_PASSWORD: string;
|
DB_PASSWORD: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
@IsString()
|
||||||
|
DEALER_ACCOUNT_ID_HIDDEN_LIST: string;
|
||||||
|
|
||||||
// .env.local
|
// .env.local
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
|
|||||||
@ -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>(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 () => {
|
it('0件でもDealerを取得できる', async () => {
|
||||||
if (!source) fail();
|
if (!source) fail();
|
||||||
const module = await makeTestingModule(source);
|
const module = await makeTestingModule(source);
|
||||||
|
|||||||
@ -72,9 +72,13 @@ import {
|
|||||||
WorktypeIdNotFoundError,
|
WorktypeIdNotFoundError,
|
||||||
} from '../../repositories/worktypes/errors/types';
|
} from '../../repositories/worktypes/errors/types';
|
||||||
import { getUserNameAndMailAddress } from '../../gateways/adb2c/utils/utils';
|
import { getUserNameAndMailAddress } from '../../gateways/adb2c/utils/utils';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
|
// プロダクト バックログ項目 4077: [保守]本番環境動作確認用のDealerアカウントを表示しないようにする の対応
|
||||||
|
private readonly dealerAccountIdHiddenList: number[] = [];
|
||||||
|
private readonly logger = new Logger(AccountsService.name);
|
||||||
constructor(
|
constructor(
|
||||||
private readonly accountRepository: AccountsRepositoryService,
|
private readonly accountRepository: AccountsRepositoryService,
|
||||||
private readonly licensesRepository: LicensesRepositoryService,
|
private readonly licensesRepository: LicensesRepositoryService,
|
||||||
@ -84,8 +88,27 @@ export class AccountsService {
|
|||||||
private readonly adB2cService: AdB2cService,
|
private readonly adB2cService: AdB2cService,
|
||||||
private readonly sendgridService: SendGridService,
|
private readonly sendgridService: SendGridService,
|
||||||
private readonly blobStorageService: BlobstorageService,
|
private readonly blobStorageService: BlobstorageService,
|
||||||
) {}
|
private readonly configService: ConfigService,
|
||||||
private readonly logger = new Logger(AccountsService.name);
|
) {
|
||||||
|
const dealerAccountIdList = this.configService.get<string>(
|
||||||
|
'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
|
* @param accountId
|
||||||
@ -1174,9 +1197,26 @@ export class AccountsService {
|
|||||||
const dealerAccounts = await this.accountRepository.findDealerAccounts(
|
const dealerAccounts = await this.accountRepository.findDealerAccounts(
|
||||||
context,
|
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 = {
|
const dealers: GetDealersResponse = {
|
||||||
dealers: dealerAccounts.map((dealerAccount): Dealer => {
|
dealers: filteredDealerAccounts.map((dealerAccount): Dealer => {
|
||||||
return {
|
return {
|
||||||
id: dealerAccount.id,
|
id: dealerAccount.id,
|
||||||
name: dealerAccount.company_name,
|
name: dealerAccount.company_name,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user