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