diff options
Diffstat (limited to 'lib/approval-template/service.ts')
| -rw-r--r-- | lib/approval-template/service.ts | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/lib/approval-template/service.ts b/lib/approval-template/service.ts index cb687c4f..4b92b817 100644 --- a/lib/approval-template/service.ts +++ b/lib/approval-template/service.ts @@ -19,6 +19,7 @@ import { } from '@/db/schema/knox/approvals'; import { filterColumns } from '@/lib/filter-columns'; +import { GetApprovalTemplateSchema } from './validations'; // --------------------------------------------- // Types @@ -45,16 +46,7 @@ export interface ApprovalTemplateWithVariables extends ApprovalTemplate { // List & read helpers // --------------------------------------------- -interface ListInput { - page: number; - perPage: number; - search?: string; - filters?: Record<string, unknown>[]; - joinOperator?: 'and' | 'or'; - sort?: Array<{ id: string; desc: boolean }>; -} - -export async function getApprovalTemplateList(input: ListInput) { +export async function getApprovalTemplateList(input: GetApprovalTemplateSchema) { const offset = (input.page - 1) * input.perPage; /* ------------------------------------------------------------------ @@ -79,15 +71,17 @@ export async function getApprovalTemplateList(input: ListInput) { } const conditions = []; + if (advancedWhere) conditions.push(advancedWhere); if (globalWhere) conditions.push(globalWhere); - const where = - conditions.length === 0 - ? undefined - : conditions.length === 1 - ? conditions[0] - : and(...conditions); + let finalWhere; + if (conditions.length > 0) { + finalWhere = conditions.length > 1 ? and(...conditions) : conditions[0]; + } + + // 아니면 ilike, inArray, gte 등으로 where 절 구성 + const where = finalWhere; /* ------------------------------------------------------------------ * ORDER BY 절 구성 @@ -97,16 +91,14 @@ export async function getApprovalTemplateList(input: ListInput) { orderBy = input.sort && input.sort.length > 0 ? input.sort .map((item) => { - if (!item || !item.id || typeof item.id !== 'string') return null; - if (!(item.id in approvalTemplates)) return null; - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - const col = approvalTemplates[item.id]; + if (!item || !item.id || typeof item.id !== "string" || !(item.id in approvalTemplates)) return null; + const col = approvalTemplates[item.id as keyof typeof approvalTemplates]; return item.desc ? desc(col) : asc(col); }) .filter((v): v is Exclude<typeof v, null> => v !== null) : [desc(approvalTemplates.updatedAt)]; - } catch { + } catch (orderErr) { + console.error("Error building order by:", orderErr); orderBy = [desc(approvalTemplates.updatedAt)]; } @@ -313,9 +305,14 @@ export async function duplicateApprovalTemplate( variables: existing.variables?.map((v) => ({ variableName: v.variableName, variableType: v.variableType, - defaultValue: v.defaultValue, - description: v.description, - })), + defaultValue: v.defaultValue ?? undefined, + description: v.description ?? undefined, + })) as Array<{ + variableName: string; + variableType: string; + defaultValue?: string; + description?: string; + }>, }) return { success: true, data: duplicated } |
