From 59b5715ebb3e1fd7bd4eb02ce50399715734f865 Mon Sep 17 00:00:00 2001 From: 0-Zz-ang Date: Mon, 4 Aug 2025 14:59:15 +0900 Subject: (박서영) docu-list-rule detail sheet 컴포넌트 추가 및 검색 필터 기능 오류 수정 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/docu-list-rule/combo-box-settings/service.ts | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'lib/docu-list-rule/combo-box-settings/service.ts') diff --git a/lib/docu-list-rule/combo-box-settings/service.ts b/lib/docu-list-rule/combo-box-settings/service.ts index 2c5ee42b..80c1942d 100644 --- a/lib/docu-list-rule/combo-box-settings/service.ts +++ b/lib/docu-list-rule/combo-box-settings/service.ts @@ -74,7 +74,7 @@ export async function getComboBoxCodeGroups(input: { } // 정렬 (안전한 필드 체크 적용) - let orderBy = sql`${codeGroups.createdAt} DESC` + let orderBy = sql`${codeGroups.groupId} ASC` if (sort && sort.length > 0) { const sortField = sort[0] // 안전성 체크: 필드가 실제 테이블에 존재하는지 확인 @@ -155,7 +155,7 @@ export async function getComboBoxOptions(codeGroupId: number, input?: { } // 정렬 (안전한 필드 체크 적용) - let orderBy = sql`${comboBoxSettings.createdAt} DESC` + let orderBy = sql`${comboBoxSettings.code} ASC` if (sort && sort.length > 0) { const sortField = sort[0] // 안전성 체크: 필드가 실제 테이블에 존재하는지 확인 @@ -281,6 +281,36 @@ export async function updateComboBoxOption(input: { remark?: string }) { try { + // 현재 수정 중인 항목의 codeGroupId 가져오기 + const currentOption = await db + .select({ codeGroupId: comboBoxSettings.codeGroupId }) + .from(comboBoxSettings) + .where(eq(comboBoxSettings.id, input.id)) + .limit(1) + + if (currentOption.length === 0) { + return { + success: false, + error: "Option not found" + } + } + + // 코드 중복 체크 (현재 수정 중인 항목 제외) + const existingOption = await db + .select({ id: comboBoxSettings.id }) + .from(comboBoxSettings) + .where( + sql`${comboBoxSettings.codeGroupId} = ${currentOption[0].codeGroupId} AND ${comboBoxSettings.code} = ${input.code} AND ${comboBoxSettings.id} != ${input.id}` + ) + .limit(1) + + if (existingOption.length > 0) { + return { + success: false, + error: "이미 존재하는 코드입니다." + } + } + const [updatedOption] = await db .update(comboBoxSettings) .set({ -- cgit v1.2.3