COURTRIX / src /server /validation /customer.ts
Ali-Developments's picture
Upload 125 files
ad79323 verified
Raw
History Blame Contribute Delete
2.4 kB
import { z } from "zod";
import {
customerDatePresetValues,
customerGenderValues,
sessionDatePresetValues,
} from "@/lib/constants";
const phoneRegex = /^[0-9+\s()\-]+$/;
export const customerSchema = z.object({
firstName: z
.string()
.trim()
.min(2, "ุงู„ุงุณู… ุงู„ุฃูˆู„ ู„ุงุฒู… ูŠูƒูˆู† ุญุฑููŠู† ุนู„ู‰ ุงู„ุฃู‚ู„.")
.max(60, "ุงู„ุงุณู… ุงู„ุฃูˆู„ ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู…."),
middleName: z
.string()
.trim()
.max(60, "ุงู„ุงุณู… ุงู„ุฃูˆุณุท ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู….")
.optional()
.or(z.literal("")),
lastName: z
.string()
.trim()
.min(2, "ุงุณู… ุงู„ุนูŠู„ุฉ ู„ุงุฒู… ูŠูƒูˆู† ุญุฑููŠู† ุนู„ู‰ ุงู„ุฃู‚ู„.")
.max(60, "ุงุณู… ุงู„ุนูŠู„ุฉ ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู…."),
gender: z.enum(customerGenderValues, {
error: "ุงุฎุชุงุฑ ุงู„ู†ูˆุน.",
}),
phone: z
.string()
.trim()
.min(7, "ุฑู‚ู… ุงู„ู…ูˆุจุงูŠู„ ู‚ุตูŠุฑ ุฌุฏู‹ุง.")
.max(30, "ุฑู‚ู… ุงู„ู…ูˆุจุงูŠู„ ุทูˆูŠู„ ุฒูŠุงุฏุฉ ุนู† ุงู„ู„ุฒูˆู….")
.regex(phoneRegex, "ุฑู‚ู… ุงู„ู…ูˆุจุงูŠู„ ู„ุงุฒู… ูŠุญุชูˆูŠ ุนู„ู‰ ุฃุฑู‚ุงู… ูˆุฑู…ูˆุฒ ุตุญูŠุญุฉ ุจุณ."),
});
export const customerListQuerySchema = z.object({
search: z.string().trim().max(100).optional().catch(undefined),
gender: z.enum(customerGenderValues).optional().catch(undefined),
createdPreset: z
.enum(customerDatePresetValues)
.optional()
.catch(undefined)
.default("all"),
page: z.coerce.number().int().min(1).optional().catch(1).default(1),
});
export const customerDetailsQuerySchema = z.object({
tab: z
.enum(["info", "cases", "sessions", "archive"])
.optional()
.catch(undefined),
caseSearch: z.string().trim().max(100).optional().catch(undefined),
caseType: z
.enum(["CIVIL", "CRIMINAL", "PERSONAL_STATUS"])
.optional()
.catch(undefined),
archiveSearch: z.string().trim().max(100).optional().catch(undefined),
archiveFileId: z.string().trim().optional().catch(undefined),
sessionPreset: z
.enum(sessionDatePresetValues)
.optional()
.catch(undefined)
.default("all"),
sessionId: z.string().trim().optional().catch(undefined),
});
export type CustomerInput = z.infer<typeof customerSchema>;
export type CustomerListQueryInput = z.infer<typeof customerListQuerySchema>;
export type CustomerDetailsQueryInput = z.infer<typeof customerDetailsQuerySchema>;