From cb68c16eb89fd13d690cd1065ba089333609dd33 Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Thu, 22 Feb 2024 08:23:31 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20775:=20=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E3=83=84=E3=83=BC=E3=83=AB=E3=81=AE=E3=83=90=E3=83=AA=E3=83=87?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3570: データ変換ツール(きれいなデータ版)作成+動作確認](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3570) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) ## レビューポイント - 特にレビューしてほしい箇所 - 軽微なものや自明なものは記載不要 - 修正範囲が大きい場合などに記載 - 全体的にや仕様を満たしているか等は本当に必要な時のみ記載 ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など ## 補足 - 相談、参考資料などがあれば --- .../server/src/constants/index.ts | 2 +- .../features/transfer/transfer.controller.ts | 4 ++ .../src/features/transfer/transfer.service.ts | 64 +++++++++++-------- 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/data_migration_tools/server/src/constants/index.ts b/data_migration_tools/server/src/constants/index.ts index 4330bb6..71bd022 100644 --- a/data_migration_tools/server/src/constants/index.ts +++ b/data_migration_tools/server/src/constants/index.ts @@ -343,7 +343,7 @@ export const MIGRATION_TYPE = { export const COUNTRY_LIST = [ { value: "CA", label: "Canada" }, { value: "KY", label: "Cayman Islands" }, - { value: "US", label: "U.S.A." }, + { value: "US", label: "United States" }, { value: "AU", label: "Australia" }, { value: "NZ", label: "New Zealand" }, { value: "AT", label: "Austria" }, diff --git a/data_migration_tools/server/src/features/transfer/transfer.controller.ts b/data_migration_tools/server/src/features/transfer/transfer.controller.ts index 59f90fc..8725a4c 100644 --- a/data_migration_tools/server/src/features/transfer/transfer.controller.ts +++ b/data_migration_tools/server/src/features/transfer/transfer.controller.ts @@ -78,6 +78,10 @@ export class TransferController { let csvInputFile: csvInputFile[] = []; csvInputFileLines.forEach((line) => { const data = line.split(","); + // ダブルクォーテーションは削除 + data.forEach((value, index) => { + data[index] = value.replace(/"/g, ""); + }); csvInputFile.push({ type: data[0], account_id: data[1], diff --git a/data_migration_tools/server/src/features/transfer/transfer.service.ts b/data_migration_tools/server/src/features/transfer/transfer.service.ts index 24f93de..5a7a58a 100644 --- a/data_migration_tools/server/src/features/transfer/transfer.service.ts +++ b/data_migration_tools/server/src/features/transfer/transfer.service.ts @@ -173,6 +173,7 @@ export class TransferService { try { // dealerAccountIdを検索し、typeがCountryの場合 accountsOutputFileStep1.forEach((account) => { + console.log(account); if (account.type === MIGRATION_TYPE.COUNTRY) { // そのacccountIdをdealerAccountIdにもつアカウント(Distributor)を検索する const distributor = accountsOutputFileStep1.find( @@ -304,6 +305,7 @@ export class TransferService { if ( line.type !== MIGRATION_TYPE.ADMINISTRATOR && line.type !== MIGRATION_TYPE.BC && + line.type !== MIGRATION_TYPE.COUNTRY && line.type !== MIGRATION_TYPE.DISTRIBUTOR && line.type !== MIGRATION_TYPE.DEALER && line.type !== MIGRATION_TYPE.CUSTOMER && @@ -315,35 +317,47 @@ export class TransferService { ); } // countryのバリデーションチェック - if (!COUNTRY_LIST.find((country) => country.label === line.country)) { - throw new HttpException( - `country is invalid. index=${index} country=${line.country}`, - HttpStatus.BAD_REQUEST - ); + if (line.country) { + if (!COUNTRY_LIST.find((country) => country.label === line.country)) { + console.log(line.country); + throw new HttpException( + `country is invalid. index=${index} country=${line.country}`, + HttpStatus.BAD_REQUEST + ); + } } // mailのバリデーションチェック // メールアドレスの形式が正しいかどうかのチェック - const mailRegExp = new RegExp( - /^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+$/ - ); - if (!mailRegExp.test(line.email)) { - throw new HttpException( - `email is invalid. index=${index} email=${line.email}`, - HttpStatus.BAD_REQUEST - ); + const mailRegExp = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; + if (line.email) { + if (!mailRegExp.test(line.email)) { + throw new HttpException( + `email is invalid. index=${index} email=${line.email}`, + HttpStatus.BAD_REQUEST + ); + } } - // recording_modeのバリデーションチェック - // RECORDING_MODEに存在するかどうかのチェック - if ( - line.recording_mode !== RECORDING_MODE.DS2_QP && - line.recording_mode !== RECORDING_MODE.DS2_SP && - line.recording_mode !== RECORDING_MODE.DSS && - line.recording_mode !== null - ) { - throw new HttpException( - `recording_mode is invalid. index=${index} recording_mode=${line.recording_mode}`, - HttpStatus.BAD_REQUEST - ); + if (line.user_email) { + if (!mailRegExp.test(line.user_email)) { + throw new HttpException( + `user_email is invalid. index=${index} user_email=${line.email}`, + HttpStatus.BAD_REQUEST + ); + } + } + // recording_modeの値が存在する場合 + if (line.recording_mode) { + // recording_modeのバリデーションチェック + if ( + line.recording_mode !== RECORDING_MODE.DS2_QP && + line.recording_mode !== RECORDING_MODE.DS2_SP && + line.recording_mode !== RECORDING_MODE.DSS + ) { + throw new HttpException( + `recording_mode is invalid. index=${index} recording_mode=${line.recording_mode}`, + HttpStatus.BAD_REQUEST + ); + } } }); } catch (e) {