I have a custom object myItem. And I want whenever id is passed in, it will call a function myService.getName(id) to fetch the name, and adding the name to myItem.
I have
const myItem = ({type: z.string(), id:z.string().optional(), name:z.string().optional}) .refine(async(item)=>{
if (item.id) try {
const name = await myService.getName(item.id)
event.name = name
} catch (error) {
logger.error('failed', error)
}
}, {
message: 'name is fetched when id is present'
})
Why doesn’t it work?
cleoone is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.