Open friendly-tech opened 5 years ago
What's the motivation behind using a class without a ConvectorModel? ConvectorModel is the one providing all this functionality, the decorators are just flags for it.
The motivation is, i might be passing in a convector model that has child properties - i don't want these child props to be convector models as makes no sense for them to have a type or id (since they are stored inline with the parent and never accessed anywhere other than via the parent object).
Also, i want to pass in payloads that might not be convector models (into the controller), and from there i might do multiple complex create/update delete of various other convector models - ie not always simple crud - sure i can use convector model but i wont ever store that model so having an id/type seems a bit pointless on it.
Sort of like transactions in composer.
For example
class BulkTransferSomething {
@Required()
string ids: Array<string>;
@Required()
string to: string;
@Required()
somethingElse: string;
}
You can still use ConvectorModels for those cases. When you declare an inner property to be FlatConvectorModel<BulkTransferSomething>
it will ignore the id and type field in the end result.
As I mentioned, the core logic for validations is inside the ConvectorModel class, if you don't use it, unexpected things might happen.
Great i will try that on the inner properties.
Regarding the 'simple object' as a controller method param - can i possibly do something like this FlatConvectorModel<BulkTransferSomething>
as a @Param() in my controller method.
@Invokable()
public async save(@Param(yup.object().shape(whatever...))
arg: FlatConvectorModel<BulkTransferSomething>): Promise<any> {
}
The problem
When creating a convector model which has properties which are simple classes, properties decorated with @Require() on this child class are ignored.
Details
Having a property on a convector model that points to another class, then on that child class i have a required property - the save does not fail if i do not pass this value in for this property.
See This issue for code setup, just add a Required() attribute to one of the properties on the child class.