코드 스타일 정리
This commit is contained in:
parent
318652b577
commit
4ed663804d
|
|
@ -412,16 +412,17 @@ export class CommonCodeController {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const validFields = ['categoryCode', 'categoryName', 'categoryNameEng'];
|
const validFields = ["categoryCode", "categoryName", "categoryNameEng"];
|
||||||
if (!validFields.includes(field as string)) {
|
if (!validFields.includes(field as string)) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "field는 categoryCode, categoryName, categoryNameEng 중 하나여야 합니다.",
|
message:
|
||||||
|
"field는 categoryCode, categoryName, categoryNameEng 중 하나여야 합니다.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.commonCodeService.checkCategoryDuplicate(
|
const result = await this.commonCodeService.checkCategoryDuplicate(
|
||||||
field as 'categoryCode' | 'categoryName' | 'categoryNameEng',
|
field as "categoryCode" | "categoryName" | "categoryNameEng",
|
||||||
value as string,
|
value as string,
|
||||||
excludeCode as string
|
excludeCode as string
|
||||||
);
|
);
|
||||||
|
|
@ -431,7 +432,7 @@ export class CommonCodeController {
|
||||||
data: {
|
data: {
|
||||||
...result,
|
...result,
|
||||||
field,
|
field,
|
||||||
value
|
value,
|
||||||
},
|
},
|
||||||
message: "카테고리 중복 검사 완료",
|
message: "카테고리 중복 검사 완료",
|
||||||
});
|
});
|
||||||
|
|
@ -462,17 +463,18 @@ export class CommonCodeController {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const validFields = ['codeValue', 'codeName', 'codeNameEng'];
|
const validFields = ["codeValue", "codeName", "codeNameEng"];
|
||||||
if (!validFields.includes(field as string)) {
|
if (!validFields.includes(field as string)) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
success: false,
|
success: false,
|
||||||
message: "field는 codeValue, codeName, codeNameEng 중 하나여야 합니다.",
|
message:
|
||||||
|
"field는 codeValue, codeName, codeNameEng 중 하나여야 합니다.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.commonCodeService.checkCodeDuplicate(
|
const result = await this.commonCodeService.checkCodeDuplicate(
|
||||||
categoryCode,
|
categoryCode,
|
||||||
field as 'codeValue' | 'codeName' | 'codeNameEng',
|
field as "codeValue" | "codeName" | "codeNameEng",
|
||||||
value as string,
|
value as string,
|
||||||
excludeCode as string
|
excludeCode as string
|
||||||
);
|
);
|
||||||
|
|
@ -483,7 +485,7 @@ export class CommonCodeController {
|
||||||
...result,
|
...result,
|
||||||
categoryCode,
|
categoryCode,
|
||||||
field,
|
field,
|
||||||
value
|
value,
|
||||||
},
|
},
|
||||||
message: "코드 중복 검사 완료",
|
message: "코드 중복 검사 완료",
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -422,7 +422,7 @@ export class CommonCodeService {
|
||||||
* 카테고리 중복 검사
|
* 카테고리 중복 검사
|
||||||
*/
|
*/
|
||||||
async checkCategoryDuplicate(
|
async checkCategoryDuplicate(
|
||||||
field: 'categoryCode' | 'categoryName' | 'categoryNameEng',
|
field: "categoryCode" | "categoryName" | "categoryNameEng",
|
||||||
value: string,
|
value: string,
|
||||||
excludeCategoryCode?: string
|
excludeCategoryCode?: string
|
||||||
): Promise<{ isDuplicate: boolean; message: string }> {
|
): Promise<{ isDuplicate: boolean; message: string }> {
|
||||||
|
|
@ -430,7 +430,7 @@ export class CommonCodeService {
|
||||||
if (!value || !value.trim()) {
|
if (!value || !value.trim()) {
|
||||||
return {
|
return {
|
||||||
isDuplicate: false,
|
isDuplicate: false,
|
||||||
message: "값을 입력해주세요."
|
message: "값을 입력해주세요.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -439,13 +439,13 @@ export class CommonCodeService {
|
||||||
|
|
||||||
// 필드별 검색 조건 설정
|
// 필드별 검색 조건 설정
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'categoryCode':
|
case "categoryCode":
|
||||||
whereCondition.category_code = trimmedValue;
|
whereCondition.category_code = trimmedValue;
|
||||||
break;
|
break;
|
||||||
case 'categoryName':
|
case "categoryName":
|
||||||
whereCondition.category_name = trimmedValue;
|
whereCondition.category_name = trimmedValue;
|
||||||
break;
|
break;
|
||||||
case 'categoryNameEng':
|
case "categoryNameEng":
|
||||||
whereCondition.category_name_eng = trimmedValue;
|
whereCondition.category_name_eng = trimmedValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -454,27 +454,27 @@ export class CommonCodeService {
|
||||||
if (excludeCategoryCode) {
|
if (excludeCategoryCode) {
|
||||||
whereCondition.category_code = {
|
whereCondition.category_code = {
|
||||||
...whereCondition.category_code,
|
...whereCondition.category_code,
|
||||||
not: excludeCategoryCode
|
not: excludeCategoryCode,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingCategory = await prisma.code_category.findFirst({
|
const existingCategory = await prisma.code_category.findFirst({
|
||||||
where: whereCondition,
|
where: whereCondition,
|
||||||
select: { category_code: true }
|
select: { category_code: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const isDuplicate = !!existingCategory;
|
const isDuplicate = !!existingCategory;
|
||||||
const fieldNames = {
|
const fieldNames = {
|
||||||
categoryCode: '카테고리 코드',
|
categoryCode: "카테고리 코드",
|
||||||
categoryName: '카테고리명',
|
categoryName: "카테고리명",
|
||||||
categoryNameEng: '카테고리 영문명'
|
categoryNameEng: "카테고리 영문명",
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDuplicate,
|
isDuplicate,
|
||||||
message: isDuplicate
|
message: isDuplicate
|
||||||
? `이미 사용 중인 ${fieldNames[field]}입니다.`
|
? `이미 사용 중인 ${fieldNames[field]}입니다.`
|
||||||
: `사용 가능한 ${fieldNames[field]}입니다.`
|
: `사용 가능한 ${fieldNames[field]}입니다.`,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`카테고리 중복 검사 중 오류 (${field}: ${value}):`, error);
|
logger.error(`카테고리 중복 검사 중 오류 (${field}: ${value}):`, error);
|
||||||
|
|
@ -487,7 +487,7 @@ export class CommonCodeService {
|
||||||
*/
|
*/
|
||||||
async checkCodeDuplicate(
|
async checkCodeDuplicate(
|
||||||
categoryCode: string,
|
categoryCode: string,
|
||||||
field: 'codeValue' | 'codeName' | 'codeNameEng',
|
field: "codeValue" | "codeName" | "codeNameEng",
|
||||||
value: string,
|
value: string,
|
||||||
excludeCodeValue?: string
|
excludeCodeValue?: string
|
||||||
): Promise<{ isDuplicate: boolean; message: string }> {
|
): Promise<{ isDuplicate: boolean; message: string }> {
|
||||||
|
|
@ -495,24 +495,24 @@ export class CommonCodeService {
|
||||||
if (!value || !value.trim()) {
|
if (!value || !value.trim()) {
|
||||||
return {
|
return {
|
||||||
isDuplicate: false,
|
isDuplicate: false,
|
||||||
message: "값을 입력해주세요."
|
message: "값을 입력해주세요.",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const trimmedValue = value.trim();
|
const trimmedValue = value.trim();
|
||||||
let whereCondition: any = {
|
let whereCondition: any = {
|
||||||
code_category: categoryCode
|
code_category: categoryCode,
|
||||||
};
|
};
|
||||||
|
|
||||||
// 필드별 검색 조건 설정
|
// 필드별 검색 조건 설정
|
||||||
switch (field) {
|
switch (field) {
|
||||||
case 'codeValue':
|
case "codeValue":
|
||||||
whereCondition.code_value = trimmedValue;
|
whereCondition.code_value = trimmedValue;
|
||||||
break;
|
break;
|
||||||
case 'codeName':
|
case "codeName":
|
||||||
whereCondition.code_name = trimmedValue;
|
whereCondition.code_name = trimmedValue;
|
||||||
break;
|
break;
|
||||||
case 'codeNameEng':
|
case "codeNameEng":
|
||||||
whereCondition.code_name_eng = trimmedValue;
|
whereCondition.code_name_eng = trimmedValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -521,30 +521,33 @@ export class CommonCodeService {
|
||||||
if (excludeCodeValue) {
|
if (excludeCodeValue) {
|
||||||
whereCondition.code_value = {
|
whereCondition.code_value = {
|
||||||
...whereCondition.code_value,
|
...whereCondition.code_value,
|
||||||
not: excludeCodeValue
|
not: excludeCodeValue,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const existingCode = await prisma.code_info.findFirst({
|
const existingCode = await prisma.code_info.findFirst({
|
||||||
where: whereCondition,
|
where: whereCondition,
|
||||||
select: { code_value: true }
|
select: { code_value: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
const isDuplicate = !!existingCode;
|
const isDuplicate = !!existingCode;
|
||||||
const fieldNames = {
|
const fieldNames = {
|
||||||
codeValue: '코드값',
|
codeValue: "코드값",
|
||||||
codeName: '코드명',
|
codeName: "코드명",
|
||||||
codeNameEng: '코드 영문명'
|
codeNameEng: "코드 영문명",
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isDuplicate,
|
isDuplicate,
|
||||||
message: isDuplicate
|
message: isDuplicate
|
||||||
? `이미 사용 중인 ${fieldNames[field]}입니다.`
|
? `이미 사용 중인 ${fieldNames[field]}입니다.`
|
||||||
: `사용 가능한 ${fieldNames[field]}입니다.`
|
: `사용 가능한 ${fieldNames[field]}입니다.`,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`코드 중복 검사 중 오류 (${categoryCode}, ${field}: ${value}):`, error);
|
logger.error(
|
||||||
|
`코드 중복 검사 중 오류 (${categoryCode}, ${field}: ${value}):`,
|
||||||
|
error
|
||||||
|
);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue