Hi,
I'm trying to write a decorator that will be used on a parameter in a controller route function. I'm trying to supply it with an object, but the parameter that comes back in the decorator function is coming in as undefined. a string type does not have the same issue, so I'm wondering if that's a limitation of decorators. Here's what I'm trying:
export const ParsedBodyDecorator = createParamDecorator<ZodObject<ZodRawShape>>(
(schema, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest<Request>();
const result = schema.safeParse(request.body); // ERROR: schema is undefined
if (!result.success) {
throw new BadRequestException(result.error);
}
return result.data;
},
);
And I'm using it in a route function like:
@ParsedBodyDecorator(mySchema) data: value