I`m looking for a "clean way" to validate if a field of my schema should be required. Usually I know this before accessing the domain layer, but I have ran into a particular scenario.
export const createOfferSchema = {
body: z
.object({
product_id: z.string(),
cycle_id: z.string(),
amount: z.coerce.number(),
price: z.coerce.number(),
description: z.string().optional(),
expires_at: z
.string()
.regex(/^\d{2}-\d{2}-\d{4}$/, "Formato esperado: DD-MM-YYYY")
.optional(),
})
.refine(notEmpty.validation, notEmpty.warning),
};
I`m currently checking if product PERISHABLE property is true inside the use-case and throwing an error if the expires_at field is not provided, but would prefer to keep the validation only on the controller. Any ideas on how to achieve this directly on the controller?