드래그앤 드랍 및 검색 및 핕터링 기능 구현
This commit is contained in:
@@ -344,7 +344,27 @@ export class CommonCodeService {
|
||||
updatedBy: string
|
||||
) {
|
||||
try {
|
||||
const updatePromises = codes.map(({ codeValue, sortOrder }) =>
|
||||
// 먼저 존재하는 코드들을 확인
|
||||
const existingCodes = await prisma.code_info.findMany({
|
||||
where: {
|
||||
code_category: categoryCode,
|
||||
code_value: { in: codes.map((c) => c.codeValue) },
|
||||
},
|
||||
select: { code_value: true },
|
||||
});
|
||||
|
||||
const existingCodeValues = existingCodes.map((c) => c.code_value);
|
||||
const validCodes = codes.filter((c) =>
|
||||
existingCodeValues.includes(c.codeValue)
|
||||
);
|
||||
|
||||
if (validCodes.length === 0) {
|
||||
throw new Error(
|
||||
`카테고리 ${categoryCode}에 순서를 변경할 유효한 코드가 없습니다.`
|
||||
);
|
||||
}
|
||||
|
||||
const updatePromises = validCodes.map(({ codeValue, sortOrder }) =>
|
||||
prisma.code_info.update({
|
||||
where: {
|
||||
code_category_code_value: {
|
||||
@@ -361,7 +381,19 @@ export class CommonCodeService {
|
||||
);
|
||||
|
||||
await Promise.all(updatePromises);
|
||||
logger.info(`코드 순서 변경 완료: ${categoryCode} - ${codes.length}개`);
|
||||
|
||||
const skippedCodes = codes.filter(
|
||||
(c) => !existingCodeValues.includes(c.codeValue)
|
||||
);
|
||||
if (skippedCodes.length > 0) {
|
||||
logger.warn(
|
||||
`코드 순서 변경 시 존재하지 않는 코드들을 건너뜀: ${skippedCodes.map((c) => c.codeValue).join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
logger.info(
|
||||
`코드 순서 변경 완료: ${categoryCode} - ${validCodes.length}개 (전체 ${codes.length}개 중)`
|
||||
);
|
||||
} catch (error) {
|
||||
logger.error(`코드 순서 변경 중 오류 (${categoryCode}):`, error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user