diff options
Diffstat (limited to 'lib/docu-list-rule/combo-box-settings/service.ts')
| -rw-r--r-- | lib/docu-list-rule/combo-box-settings/service.ts | 34 |
1 files changed, 32 insertions, 2 deletions
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({ |
