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) {