Merged PR 775: 変換ツールのバリデーションチェックを修正

## 概要
[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環境で確認など

## 補足
- 相談、参考資料などがあれば
This commit is contained in:
maruyama.t 2024-02-22 08:23:31 +00:00
parent c31bb47bb8
commit cb68c16eb8
3 changed files with 44 additions and 26 deletions

View File

@ -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" },

View File

@ -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],

View File

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