summaryrefslogtreecommitdiff
path: root/lib/file-download-log/validation.ts
blob: bf888e9cd5fd10ec2e1af0748add351e6f6f542e (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
37
import { fileDownloadLogs } from "@/db/schema";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from 'zod';

// Zod 스키마
export const fileDownloadLogInsertSchema = createInsertSchema(fileDownloadLogs);
export const fileDownloadLogSelectSchema = createSelectSchema(fileDownloadLogs);

export type FileDownloadLog = typeof fileDownloadLogs.$inferSelect;
export type NewFileDownloadLog = typeof fileDownloadLogs.$inferInsert;

// validation.ts에 추가할 타입
interface FileInfo {
    fileName?: string;
    filePath?: string;
    fileSize?: number;
  }
  
  // 수정된 입력 스키마
export const createFileDownloadLogSchema = z.object({
    fileId: z.number(),
    success: z.boolean(),
    errorMessage: z.string().optional(),
    requestId: z.string().optional(),
    downloadDurationMs: z.number().optional(),
    // 파일 정보를 직접 받을 수 있도록 추가
    fileInfo: z.object({
      fileName: z.string().optional(),
      filePath: z.string().optional(),
      fileSize: z.number().optional(),
    }).optional(),
    // 또는 다른 테이블에서 조회할 수 있도록
    fileSource: z.enum(['rfqAttachments', 'documents', 'uploads']).optional(),
  });


export type CreateFileDownloadLogInput = z.infer<typeof createFileDownloadLogSchema>;