Merged PR 788: [2回目実行]実施後の動作確認

## 概要
[Task3577: [2回目実行]実施後の動作確認](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3577)

accountがCountryの場合に配下のDistributorの親アカウントIDを付け替える処理について、Typeの付け替えができていなかったのを修正。
ライセンスの有効期限が"9999/12/31 23:59:59.997"でフォーマットチェックをしているが、移行元は"9999/12/31 23:59:59"なので移行元に合わせた。
dealerAccountIdが設定されているが、そのdealerが存在しない場合もデータを作ってしまっている。
→該当レコードはエラーファイルを出力する。

## レビューポイント
- エラーファイルの出力処理だが簡素すぎるか?
JSONで出力する意味はないが、これまでの動作確認で動作担保できているのでJSONで出しています。

## 動作確認状況
- ローカルで確認
正常の場合データ変換が行われることを確認。
dealerAccountIdが設定されているが、そのdealerが存在しない場合もデータでテストした場合、error.jsonが作られることを確認。
## 補足
- 相談、参考資料などがあれば
This commit is contained in:
maruyama.t 2024-02-27 23:55:44 +00:00
parent f0d71937e3
commit f6d39a4c26

View File

@ -50,7 +50,7 @@ export class TransferService {
let usersFileLines: UsersFile[] = [];
let licensesFileLines: LicensesFile[] = [];
let worktypesFileLines: WorktypesFile[] = [];
let errorArray: string[] = [];
let userIdIndex = 0;
// authorIdとuserIdの対応関係を保持するMapを定義
const authorIdToUserIdMap: Map<string, number> = new Map();
@ -75,9 +75,11 @@ export class TransferService {
if (line.parent_id) {
parentAccountId = accountIdMap.get(line.parent_id);
}
// 万が一parent_idが入力されているのに存在しなかった場合は、nullを設定する。
// 万が一parent_idが入力されているのに存在しなかった場合は、エラー配列に追加する
if (parentAccountId === undefined) {
parentAccountId = null;
errorArray.push(
`parent_id is invalid. parent_id=${line.parent_id}`
);
}
// userIdIndexをインクリメントする
@ -126,8 +128,8 @@ export class TransferService {
}
// ライセンスのデータの作成を行う
// line.expired_dateが9999/12/31 23:59:59.997のデータの場合はデモライセンスなので登録しない
if (line.expired_date !== "9999/12/31 23:59:59.997") {
// line.expired_dateが"9999/12/31 23:59:59"のデータの場合はデモライセンスなので登録しない
if (line.expired_date !== "9999/12/31 23:59:59") {
// authorIdが設定されてる場合、statusは"allocated"、allocated_user_idは対象のユーザID
// されていない場合、statusは"reusable"、allocated_user_idはnull
let status: string;
@ -176,6 +178,15 @@ export class TransferService {
}
}
});
// エラー配列に値が存在する場合はエラーファイルを出力する
if (errorArray.length > 0) {
const errorFileJson = JSON.stringify(errorArray);
fs.writeFileSync(`error.json`, errorFileJson);
throw new HttpException(
`errorArray is invalid. errorArray=${errorArray}`,
HttpStatus.BAD_REQUEST
);
}
return {
accountsFileTypeLines,
usersFileLines,
@ -211,24 +222,23 @@ export class TransferService {
try {
const relocatedAccounts: AccountsFile[] = [];
const countryRecords: Map<number, number> = new Map();
const dealerRecords: Map<number, number> = new Map();
// accountsFileTypeをループ
accountsFileType.forEach((account) => {
// Countryの場合はDistributorのアカウントIDと新たな親アカウントIDBCの組み合わせをMapに登録
if (account.type === MIGRATION_TYPE.COUNTRY) {
// 配下のDistributorアカウントを取得
const distributor = accountsFileType.find(
(distributor) =>
distributor.dealerAccountId === account.accountId &&
distributor.type === MIGRATION_TYPE.DISTRIBUTOR
// Distributorの場合はdealerを検索し、COUNTRYかチェックする
if (account.type === MIGRATION_TYPE.DISTRIBUTOR) {
const distributorParent = accountsFileType.find(
(a) => a.accountId === account.dealerAccountId
);
if (distributor) {
countryRecords.set(distributor.accountId, account.dealerAccountId);
if (distributorParent.type === MIGRATION_TYPE.COUNTRY) {
dealerRecords.set(
account.accountId,
distributorParent.dealerAccountId // Countryの親、BCのIDを設定
);
}
} else {
// Country以外のアカウントの場合は、そのまま登録
countryRecords.set(account.accountId, account.dealerAccountId);
dealerRecords.set(account.accountId, account.dealerAccountId);
}
});
@ -237,7 +247,7 @@ export class TransferService {
// Countryのレコードは除外する
if (account.type !== MIGRATION_TYPE.COUNTRY) {
const dealerAccountId =
countryRecords.get(account.dealerAccountId) ??
dealerRecords.get(account.dealerAccountId) ??
account.dealerAccountId;
const type = this.getAccountType(account.type);
const newAccount: AccountsFile = {