66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
import { z } from 'zod';
|
|
|
|
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
|
|
const ALLOWED_TYPES = [
|
|
'application/pdf',
|
|
'image/png',
|
|
'image/jpg',
|
|
'image/jpeg',
|
|
];
|
|
|
|
export const ExpenseSchema = z.object({
|
|
projectId: z.string().min(1, { message: "Project is required" }),
|
|
expensesTypeId: z.string().min(1, { message: "Expense type is required" }),
|
|
paymentModeId: z.string().min(1, { message: "Payment mode is required" }),
|
|
paidById: z.string().min(1, { message: "Employee name is required" }),
|
|
transactionDate: z.string().min(1, { message: "Date is required" }),
|
|
transactionId: z.string().optional(), // if optional, else use .min(1)
|
|
description: z.string().min(1, { message: "Description is required" }),
|
|
location: z.string().min(1, { message: "Location is required" }),
|
|
supplerName: z.string().min(1, { message: "Supplier name is required" }),
|
|
amount: z.number().min(1, { message: "Amount must be at least 1" }).max(10000, { message: "Amount must not exceed 10,000" }),
|
|
noOfPersons: z.number().min(1, { message: "1 Employee at least required" }),
|
|
statusId: z.string().min(1, { message: "Please select status" }),
|
|
|
|
billAttachments: z
|
|
.array(
|
|
z.object({
|
|
fileName: z.string().min(1, { message: "Filename is required" }),
|
|
base64Data: z.string().min(1, { message: "File data is required" }),
|
|
contentType: z.string().refine((val) => ALLOWED_TYPES.includes(val), {
|
|
message: "Only PDF, PNG, JPG, or JPEG files are allowed",
|
|
}),
|
|
fileSize: z.number().max(MAX_FILE_SIZE, {
|
|
message: "File size must be less than or equal to 5MB",
|
|
}),
|
|
description: z.string().optional(),
|
|
})
|
|
)
|
|
.nonempty({ message: "At least one file attachment is required" }),
|
|
});
|
|
|
|
|
|
let payload=
|
|
{
|
|
"projectId": "2618f2ef-2823-11f0-9d9e-bc241163f504",
|
|
"expensesTypeId": "dd120bc4-ab0a-45ba-8450-5cd45ff221ca",
|
|
"paymentModeId": "ed667353-8eea-4fd1-8750-719405932480",
|
|
"paidById": "08dda7d8-014e-443f-858d-a55f4b484bc4",
|
|
"transactionDate": "2025-07-12T09:56:54.122Z",
|
|
"transactionId": "string",
|
|
"description": "string",
|
|
"location": "string",
|
|
"supplerName": "string",
|
|
"amount": 390,
|
|
"noOfPersons": 0,
|
|
"statusId": "297e0d8f-f668-41b5-bfea-e03b354251c8",
|
|
"billAttachments": [
|
|
{
|
|
"fileName": "string",
|
|
"base64Data": "string",
|
|
"contentType": "string",
|
|
"fileSize": 0,
|
|
"description": "string"
|
|
}
|
|
]
|
|
} |