Adding auto trim in Schema of Recurring Expense.
This commit is contained in:
parent
ac9eaa1e67
commit
0372991ac1
@ -1,16 +1,65 @@
|
|||||||
import { boolean, z } from "zod";
|
import { boolean, z } from "zod";
|
||||||
import { INR_CURRENCY_CODE } from "../../utils/constants";
|
import { INR_CURRENCY_CODE } from "../../utils/constants";
|
||||||
|
|
||||||
|
// export const PaymentRecurringExpense = (expenseTypes) => {
|
||||||
|
// return z
|
||||||
|
// .object({
|
||||||
|
// title: z.string().min(1, { message: "Project is required" }),
|
||||||
|
|
||||||
|
// description: z.string().min(1, { message: "Description is required" }),
|
||||||
|
|
||||||
|
// payee: z.string().min(1, { message: "Supplier name is required" }),
|
||||||
|
|
||||||
|
// notifyTo: z.string().min(1, { message: "Notification is required" }),
|
||||||
|
|
||||||
|
// currencyId: z
|
||||||
|
// .string()
|
||||||
|
// .min(1, { message: "Currency is required" }),
|
||||||
|
|
||||||
|
// 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",
|
||||||
|
// }),
|
||||||
|
|
||||||
|
// strikeDate: z.string().min(1, { message: "Date is required" }),
|
||||||
|
|
||||||
|
// projectId: z.string().min(1, { message: "Project is required" }),
|
||||||
|
|
||||||
|
// paymentBufferDays: z.string().min(1, { message: "Buffer days is required" }),
|
||||||
|
|
||||||
|
// numberOfIteration: z.string().min(1, { message: "Iteration is required" }),
|
||||||
|
|
||||||
|
// expenseCategoryId: z
|
||||||
|
// .string()
|
||||||
|
// .min(1, { message: "Expense Category is required" }),
|
||||||
|
|
||||||
|
// statusId: z.string().min(1, { message: "Please select a status" }),
|
||||||
|
|
||||||
|
// frequency: z.string().min(1, { message: "Frequency is required" }),
|
||||||
|
|
||||||
|
// isVariable: z.boolean().optional(),
|
||||||
|
|
||||||
|
// })
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
export const PaymentRecurringExpense = (expenseTypes) => {
|
export const PaymentRecurringExpense = (expenseTypes) => {
|
||||||
return z.object({
|
return z.object({
|
||||||
title: z.string().min(1, { message: "Title is required" }).transform((val) => val.trim()),
|
title: z.string().min(1, { message: "Project is required" }),
|
||||||
description: z.string().min(1, { message: "Description is required" }).transform((val) => val.trim()),
|
|
||||||
payee: z.string().min(1, { message: "Payee name is required" }).transform((val) => val.trim()),
|
description: z.string().min(1, { message: "Description is required" }),
|
||||||
notifyTo: z.string().min(1, { message: "Notification e-mail is required" }).transform((val) => val.trim()),
|
|
||||||
|
payee: z.string().min(1, { message: "Supplier name is required" }),
|
||||||
|
|
||||||
|
notifyTo: z.string().min(1, { message: "Notification is required" }),
|
||||||
|
|
||||||
currencyId: z
|
currencyId: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Currency is required" })
|
.min(1, { message: "Currency is required" }),
|
||||||
.transform((val) => val.trim()),
|
|
||||||
|
|
||||||
amount: z
|
amount: z
|
||||||
.number({
|
.number({
|
||||||
@ -27,13 +76,11 @@ export const PaymentRecurringExpense = (expenseTypes) => {
|
|||||||
.min(1, { message: "Date is required" })
|
.min(1, { message: "Date is required" })
|
||||||
.refine((val) => !isNaN(Date.parse(val)), {
|
.refine((val) => !isNaN(Date.parse(val)), {
|
||||||
message: "Invalid date format",
|
message: "Invalid date format",
|
||||||
})
|
}),
|
||||||
.transform((val) => val.trim()),
|
|
||||||
|
|
||||||
projectId: z
|
projectId: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Project is required" })
|
.min(1, { message: "Project is required" }),
|
||||||
.transform((val) => val.trim()),
|
|
||||||
|
|
||||||
paymentBufferDays: z
|
paymentBufferDays: z
|
||||||
.number({
|
.number({
|
||||||
@ -51,28 +98,23 @@ export const PaymentRecurringExpense = (expenseTypes) => {
|
|||||||
|
|
||||||
expenseCategoryId: z
|
expenseCategoryId: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Expense Category is required" })
|
.min(1, { message: "Expense Category is required" }),
|
||||||
.transform((val) => val.trim()),
|
|
||||||
|
|
||||||
statusId: z
|
statusId: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, { message: "Please select a status" })
|
.min(1, { message: "Please select a status" }),
|
||||||
.transform((val) => val.trim()),
|
|
||||||
|
|
||||||
frequency: z
|
frequency: z
|
||||||
.number({
|
.number({
|
||||||
required_error: "Frequency is required",
|
required_error: "Frequency is required",
|
||||||
invalid_type_error: "Frequency must be a number",
|
invalid_type_error: "Frequency must be a number",
|
||||||
})
|
})
|
||||||
.refine((val) => [0, 1, 2, 3, 4, 5].includes(val), {
|
.min(1, { message: "Frequency must be greater than 0" }),
|
||||||
message: "Invalid frequency selected",
|
|
||||||
}),
|
|
||||||
|
|
||||||
isVariable: z.boolean().optional(),
|
isVariable: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const defaultRecurringExpense = {
|
export const defaultRecurringExpense = {
|
||||||
title: "",
|
title: "",
|
||||||
description: "",
|
description: "",
|
||||||
@ -87,26 +129,30 @@ export const defaultRecurringExpense = {
|
|||||||
expenseCategoryId: "",
|
expenseCategoryId: "",
|
||||||
statusId: "",
|
statusId: "",
|
||||||
frequency: 1,
|
frequency: 1,
|
||||||
isVariable: true,
|
isVariable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const SearchRecurringExpenseSchema = z.object({
|
// export const SearchPaymentRequestSchema = z.object({
|
||||||
title: z.array(z.string()).optional(),
|
// projectIds: z.array(z.string()).optional(),
|
||||||
description: z.array(z.string()).optional(),
|
// statusIds: z.array(z.string()).optional(),
|
||||||
payee: z.array(z.string()).optional(),
|
// createdByIds: z.array(z.string()).optional(),
|
||||||
notifyTo: z.array(z.string()).optional(),
|
// currencyIds: z.array(z.string()).optional(),
|
||||||
currencyId: z.array(z.string()).optional(),
|
// expenseCategoryIds: z.array(z.string()).optional(),
|
||||||
amount: z.array(z.string()).optional(),
|
// payees: z.array(z.string()).optional(),
|
||||||
strikeDate: z.string().optional(),
|
// startDate: z.string().optional(),
|
||||||
projectId: z.string().optional(),
|
// endDate: z.string().optional(),
|
||||||
paymentBufferDays: z.string().optional(),
|
// });
|
||||||
numberOfIteration: z.string().optional(),
|
|
||||||
expenseCategoryId: z.string().optional(),
|
// export const defaultPaymentRequestFilter = {
|
||||||
statusId: z.string().optional(),
|
// projectIds: [],
|
||||||
frequency: z.string().optional(),
|
// statusIds: [],
|
||||||
isVariable: z.string().optional(),
|
// createdByIds: [],
|
||||||
});
|
// currencyIds: [],
|
||||||
|
// expenseCategoryIds: [],
|
||||||
|
// payees: [],
|
||||||
|
// startDate: null,
|
||||||
|
// endDate: null,
|
||||||
|
// };
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user