공통코드 관리 시스템 개선 완료
This commit is contained in:
@@ -417,4 +417,135 @@ export class CommonCodeService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 카테고리 중복 검사
|
||||
*/
|
||||
async checkCategoryDuplicate(
|
||||
field: 'categoryCode' | 'categoryName' | 'categoryNameEng',
|
||||
value: string,
|
||||
excludeCategoryCode?: string
|
||||
): Promise<{ isDuplicate: boolean; message: string }> {
|
||||
try {
|
||||
if (!value || !value.trim()) {
|
||||
return {
|
||||
isDuplicate: false,
|
||||
message: "값을 입력해주세요."
|
||||
};
|
||||
}
|
||||
|
||||
const trimmedValue = value.trim();
|
||||
let whereCondition: any = {};
|
||||
|
||||
// 필드별 검색 조건 설정
|
||||
switch (field) {
|
||||
case 'categoryCode':
|
||||
whereCondition.category_code = trimmedValue;
|
||||
break;
|
||||
case 'categoryName':
|
||||
whereCondition.category_name = trimmedValue;
|
||||
break;
|
||||
case 'categoryNameEng':
|
||||
whereCondition.category_name_eng = trimmedValue;
|
||||
break;
|
||||
}
|
||||
|
||||
// 수정 시 자기 자신 제외
|
||||
if (excludeCategoryCode) {
|
||||
whereCondition.category_code = {
|
||||
...whereCondition.category_code,
|
||||
not: excludeCategoryCode
|
||||
};
|
||||
}
|
||||
|
||||
const existingCategory = await prisma.code_category.findFirst({
|
||||
where: whereCondition,
|
||||
select: { category_code: true }
|
||||
});
|
||||
|
||||
const isDuplicate = !!existingCategory;
|
||||
const fieldNames = {
|
||||
categoryCode: '카테고리 코드',
|
||||
categoryName: '카테고리명',
|
||||
categoryNameEng: '카테고리 영문명'
|
||||
};
|
||||
|
||||
return {
|
||||
isDuplicate,
|
||||
message: isDuplicate
|
||||
? `이미 사용 중인 ${fieldNames[field]}입니다.`
|
||||
: `사용 가능한 ${fieldNames[field]}입니다.`
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(`카테고리 중복 검사 중 오류 (${field}: ${value}):`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 코드 중복 검사
|
||||
*/
|
||||
async checkCodeDuplicate(
|
||||
categoryCode: string,
|
||||
field: 'codeValue' | 'codeName' | 'codeNameEng',
|
||||
value: string,
|
||||
excludeCodeValue?: string
|
||||
): Promise<{ isDuplicate: boolean; message: string }> {
|
||||
try {
|
||||
if (!value || !value.trim()) {
|
||||
return {
|
||||
isDuplicate: false,
|
||||
message: "값을 입력해주세요."
|
||||
};
|
||||
}
|
||||
|
||||
const trimmedValue = value.trim();
|
||||
let whereCondition: any = {
|
||||
code_category: categoryCode
|
||||
};
|
||||
|
||||
// 필드별 검색 조건 설정
|
||||
switch (field) {
|
||||
case 'codeValue':
|
||||
whereCondition.code_value = trimmedValue;
|
||||
break;
|
||||
case 'codeName':
|
||||
whereCondition.code_name = trimmedValue;
|
||||
break;
|
||||
case 'codeNameEng':
|
||||
whereCondition.code_name_eng = trimmedValue;
|
||||
break;
|
||||
}
|
||||
|
||||
// 수정 시 자기 자신 제외
|
||||
if (excludeCodeValue) {
|
||||
whereCondition.code_value = {
|
||||
...whereCondition.code_value,
|
||||
not: excludeCodeValue
|
||||
};
|
||||
}
|
||||
|
||||
const existingCode = await prisma.code_info.findFirst({
|
||||
where: whereCondition,
|
||||
select: { code_value: true }
|
||||
});
|
||||
|
||||
const isDuplicate = !!existingCode;
|
||||
const fieldNames = {
|
||||
codeValue: '코드값',
|
||||
codeName: '코드명',
|
||||
codeNameEng: '코드 영문명'
|
||||
};
|
||||
|
||||
return {
|
||||
isDuplicate,
|
||||
message: isDuplicate
|
||||
? `이미 사용 중인 ${fieldNames[field]}입니다.`
|
||||
: `사용 가능한 ${fieldNames[field]}입니다.`
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(`코드 중복 검사 중 오류 (${categoryCode}, ${field}: ${value}):`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user