diff options
| author | 0-Zz-ang <s1998319@gmail.com> | 2025-07-29 09:08:52 +0900 |
|---|---|---|
| committer | 0-Zz-ang <s1998319@gmail.com> | 2025-07-29 09:11:22 +0900 |
| commit | 8d92c88ab341156d82156bae49c62a8101280e75 (patch) | |
| tree | 065ed1838de4164da23e3777b5367143e4f13982 /lib/docu-list-rule/combo-box-settings/service.ts | |
| parent | 75249e6fa46864f49d4eb91bd755171b6b65eaae (diff) | |
(박서영) 설계 Document Numbering Rule 수정
Diffstat (limited to 'lib/docu-list-rule/combo-box-settings/service.ts')
| -rw-r--r-- | lib/docu-list-rule/combo-box-settings/service.ts | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/lib/docu-list-rule/combo-box-settings/service.ts b/lib/docu-list-rule/combo-box-settings/service.ts index b603ee71..70046828 100644 --- a/lib/docu-list-rule/combo-box-settings/service.ts +++ b/lib/docu-list-rule/combo-box-settings/service.ts @@ -22,7 +22,7 @@ export async function getComboBoxCodeGroups(input: { unstable_noStore() try { - const { page, perPage, sort, search } = input + const { page, perPage, sort, search, filters, joinOperator } = input const offset = (page - 1) * perPage // Control Type이 combobox인 조건 @@ -38,33 +38,50 @@ export async function getComboBoxCodeGroups(input: { )` } - // 정렬 + // 고급 필터링 + if (filters && filters.length > 0) { + const filterConditions = filters.map(filter => { + const { id, value } = filter + if (!value) return null + + switch (id) { + case "groupId": + return sql`${codeGroups.groupId} ILIKE ${`%${value}%`}` + case "description": + return sql`${codeGroups.description} ILIKE ${`%${value}%`}` + case "codeFormat": + return sql`${codeGroups.codeFormat} ILIKE ${`%${value}%`}` + case "controlType": + return sql`${codeGroups.controlType} = ${value}` + case "isActive": + return sql`${codeGroups.isActive} = ${value === "true"}` + case "createdAt": + return sql`${codeGroups.createdAt}::text ILIKE ${`%${value}%`}` + default: + return null + } + }).filter(Boolean) + + if (filterConditions.length > 0) { + const operator = joinOperator === "or" ? sql` OR ` : sql` AND ` + const combinedFilters = filterConditions.reduce((acc, condition, index) => { + if (index === 0) return condition + return sql`${acc}${operator}${condition}` + }) + + whereConditions = sql`${whereConditions} AND (${combinedFilters})` + } + } + + // 정렬 (안전한 필드 체크 적용) let orderBy = sql`${codeGroups.createdAt} DESC` if (sort && sort.length > 0) { const sortField = sort[0] - const direction = sortField.desc ? sql`DESC` : sql`ASC` - - switch (sortField.id) { - case "groupId": - orderBy = sql`${codeGroups.groupId} ${direction}` - break - case "description": - orderBy = sql`${codeGroups.description} ${direction}` - break - case "codeFormat": - orderBy = sql`${codeGroups.codeFormat} ${direction}` - break - case "controlType": - orderBy = sql`${codeGroups.controlType} ${direction}` - break - case "isActive": - orderBy = sql`${codeGroups.isActive} ${direction}` - break - case "createdAt": - orderBy = sql`${codeGroups.createdAt} ${direction}` - break - default: - orderBy = sql`${codeGroups.createdAt} DESC` + // 안전성 체크: 필드가 실제 테이블에 존재하는지 확인 + if (sortField && sortField.id && typeof sortField.id === "string" && sortField.id in codeGroups) { + const direction = sortField.desc ? sql`DESC` : sql`ASC` + const col = codeGroups[sortField.id as keyof typeof codeGroups] + orderBy = sql`${col} ${direction}` } } @@ -137,30 +154,15 @@ export async function getComboBoxOptions(codeGroupId: number, input?: { )` } - // 정렬 + // 정렬 (안전한 필드 체크 적용) let orderBy = sql`${comboBoxSettings.createdAt} DESC` if (sort && sort.length > 0) { const sortField = sort[0] - const direction = sortField.desc ? sql`DESC` : sql`ASC` - - switch (sortField.id) { - case "code": - orderBy = sql`${comboBoxSettings.code} ${direction}` - break - case "description": - orderBy = sql`${comboBoxSettings.description} ${direction}` - break - case "remark": - orderBy = sql`${comboBoxSettings.remark} ${direction}` - break - case "createdAt": - orderBy = sql`${comboBoxSettings.createdAt} ${direction}` - break - case "updatedAt": - orderBy = sql`${comboBoxSettings.updatedAt} ${direction}` - break - default: - orderBy = sql`${comboBoxSettings.createdAt} DESC` + // 안전성 체크: 필드가 실제 테이블에 존재하는지 확인 + if (sortField && sortField.id && typeof sortField.id === "string" && sortField.id in comboBoxSettings) { + const direction = sortField.desc ? sql`DESC` : sql`ASC` + const col = comboBoxSettings[sortField.id as keyof typeof comboBoxSettings] + orderBy = sql`${col} ${direction}` } } |
