67 lines
2.1 KiB
JavaScript
67 lines
2.1 KiB
JavaScript
import { boolean, z } from "zod";
|
|
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
const ALLOWED_TYPES = [
|
|
"application/pdf",
|
|
"image/png",
|
|
"image/jpg",
|
|
"image/jpeg",
|
|
];
|
|
export const PaymentRequestSchema = (expenseTypes) => {
|
|
return z
|
|
.object({
|
|
title: z.string().min(1, { message: "Project is required" }),
|
|
projectId: z.string().min(1, { message: "Project is required" }),
|
|
expenseCategoryId: z
|
|
.string()
|
|
.min(1, { message: "Expense Category is required" }),
|
|
currencyId: z
|
|
.string()
|
|
.min(1, { message: "Currency is required" }),
|
|
dueDate: z.string().min(1, { message: "Date is required" }),
|
|
description: z.string().min(1, { message: "Description is required" }),
|
|
payee: z.string().min(1, { message: "Supplier name is required" }),
|
|
isAdvancePayment: z.boolean(),
|
|
amount: z.coerce
|
|
.number({
|
|
invalid_type_error: "Amount is required and must be a number",
|
|
})
|
|
.min(1, "Amount must be Enter")
|
|
.refine((val) => /^\d+(\.\d{1,2})?$/.test(val.toString()), {
|
|
message: "Amount must have at most 2 decimal places",
|
|
}),
|
|
billAttachments: z
|
|
.array(
|
|
z.object({
|
|
fileName: z.string().min(1, { message: "Filename is required" }),
|
|
base64Data: z.string().nullable(),
|
|
contentType: z
|
|
.string()
|
|
.refine((val) => ALLOWED_TYPES.includes(val), {
|
|
message: "Only PDF, PNG, JPG, or JPEG files are allowed",
|
|
}),
|
|
documentId: z.string().optional(),
|
|
fileSize: z.number().max(MAX_FILE_SIZE, {
|
|
message: "File size must be less than or equal to 5MB",
|
|
}),
|
|
description: z.string().optional(),
|
|
isActive: z.boolean().default(true),
|
|
})
|
|
)
|
|
,
|
|
})
|
|
};
|
|
|
|
export const defaultPaymentRequest = {
|
|
title:"",
|
|
description: "",
|
|
payee: "",
|
|
currencyId: "",
|
|
amount: "",
|
|
dueDate: "",
|
|
projectId: "",
|
|
expenseCategoryId: "",
|
|
isAdvancePayment:boolean,
|
|
billAttachments: [],
|
|
};
|
|
|