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
37
38
39
40
41
42
43
44
|
import {
createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { pageVisits, users } from "@/db/schema"
// 조인된 데이터 타입 정의
export type ExtendedPageVisit = typeof pageVisits.$inferSelect & {
userEmail?: string | null;
userName?: string | null;
durationFormatted?: string; // 계산된 필드
isLongVisit?: boolean; // 5분 이상 체류
};
// 검색 파라미터 캐시 정의
export const searchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
// 정렬
sort: getSortingStateParser<ExtendedPageVisit>().withDefault([
{ id: "visitedAt", desc: true },
]),
// 기본 필터
route: parseAsString.withDefault(""),
deviceType: parseAsString.withDefault(""),
browserName: parseAsString.withDefault(""),
// 고급 필터
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
});
// 타입 내보내기
export type GetPageVisitsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>;
|