eletrotupi / tcc/ api/src/schemas/insight.schema.tsb36ca93521cd90a436cca219f26ba8cb906448f4
532 B | 16 lines Raw
1
import { z } from 'zod';
2
import { isMatch } from 'date-fns';
3
import { InsightPeriod, InsightType } from '@prisma/client';
4

5
export const InsightsQuerySchema = z.object({
6
  type: z.nativeEnum(InsightType).optional(),
7
  period: z.nativeEnum(InsightPeriod).optional(),
8
  limit: z.coerce.number().int().positive().max(100).optional(),
9
  day: z
10
    .string()
11
    .regex(/^\d{4}-\d{2}-\d{2}$/)
12
    .refine((value) => isMatch(value, 'yyyy-MM-dd'))
13
    .optional(),
14
});
15

16
export type InsightsQueryInput = z.infer<typeof InsightsQuerySchema>;