summaryrefslogtreecommitdiff
path: root/lib/integration-log/validations.ts
blob: 41bc68604e4952a8ed16e5660e44ed5fb811ad37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {
  createSearchParamsCache,
  parseAsArrayOf,
  parseAsInteger,
  parseAsString,
  parseAsStringEnum,
} from "nuqs/server";
import * as z from "zod";

import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers";
import { integrationLogTable } from "@/db/schema/integration-log";

export const SearchParamsCache = createSearchParamsCache({
  // UI 모드나 플래그 관련
  flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),

  // 페이징
  page: parseAsInteger.withDefault(1),
  perPage: parseAsInteger.withDefault(10),
    
  // 정렬 (executionTime 기준 내림차순)
  sort: getSortingStateParser<typeof integrationLogTable>().withDefault([
    { id: "executionTime", desc: true }
  ]),

  // 필터링 필드
  status: parseAsString.withDefault(""),
  action: parseAsString.withDefault(""),
  executedBy: parseAsString.withDefault(""),
  interfaceId: parseAsInteger.withDefault(0),
  filters: getFiltersStateParser().withDefault([]),
  joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
  search: parseAsString.withDefault(""),
});

export type GetIntegrationLogsSchema = Awaited<ReturnType<typeof SearchParamsCache.parse>>;