How can be Zod validation for an abject within another object (with validation message to this object itself), where the object is selt is required and the values within minght be optional (depanding upon the scenario) #3948
Unanswered
swapnesh839
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
export const CreateEventvalidation = {
body: z.object({
// parkName: z.string({ message: "parkName is required" }),
title: z
.string({ message: "title is required" })
.min(4, "title should be at least 4 characters long"),
status: z
.string({ message: "status is required" })
.min(4, "status should be at least 4 characters long"),
type: z
.string({ message: "type is required" })
.min(4, "type should be at least 4 characters long"),
startDate: z.string({ message: "startDate is required" }),
endDate: z.string({ message: "endDate is required" }),
RelatedPark: z
.object({
parkName: z.string({ message: "parkName is required" }),
_id: z.string({ message: "_id is required" }),
})
.refine((data) => !!data.parkName && !!data._id, {
message: "RelatedPark must include valid parkName and _id",
}),
description: z
.string({ message: "description is required" })
.min(4, "description should be at least 4 characters long"),
}),
};
Beta Was this translation helpful? Give feedback.
All reactions