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
45
|
// app/admin/sessions/login-history/validation.ts
import {
createSearchParamsCache,
parseAsArrayOf,
parseAsInteger,
parseAsString,
parseAsStringEnum,
} from "nuqs/server"
import * as z from "zod"
import { getFiltersStateParser, getSortingStateParser } from "@/lib/parsers"
import { loginSessions, users } from "@/db/schema"
// 조인된 데이터 타입 정의
export type ExtendedLoginSession = typeof loginSessions.$inferSelect & {
userEmail: string;
userName: string;
sessionDuration?: number; // 계산된 필드
isCurrentlyActive: boolean; // 계산된 필드
};
// 검색 파라미터 캐시 정의
export const searchParamsCache = createSearchParamsCache({
flags: parseAsArrayOf(z.enum(["advancedTable", "floatingBar"])).withDefault([]),
page: parseAsInteger.withDefault(1),
perPage: parseAsInteger.withDefault(10),
// 정렬
sort: getSortingStateParser<ExtendedLoginSession>().withDefault([
{ id: "loginAt", desc: true },
]),
// 기본 필터
userEmail: parseAsString.withDefault(""),
authMethod: parseAsString.withDefault(""),
isActive: parseAsString.withDefault(""),
// 고급 필터
filters: getFiltersStateParser().withDefault([]),
joinOperator: parseAsStringEnum(["and", "or"]).withDefault("and"),
search: parseAsString.withDefault(""),
});
// 타입 내보내기
export type GetLoginSessionsSchema = Awaited<ReturnType<typeof searchParamsCache.parse>>;
|