convector icon indicating copy to clipboard operation
convector copied to clipboard

Better support for arrays for @Param() decorator

Open friendly-tech opened this issue 5 years ago • 1 comments

When you have a param into a controller method that is an array you need to specify the array schema manually.

public async saveBulk(
@Param(yup.array().transform(values => values.map(v => new MyModel(v)))) 
bulkItems: Array<MyModel>): Promise<any> { ... }

but it would be nice if the @Param() decorator could detect the array input type and handle it accordingly, this may well apply to the Validate() decorator as well.

friendly-tech avatar Mar 05 '19 19:03 friendly-tech

You can have a better syntax by doing yup.array().of(MyModel.schema()), even tho, we're missing the transform piece in the .schema() method.

I'll keep this open to add that missing piece to the method. Thanks for reporting.

diestrin avatar May 30 '19 20:05 diestrin