Closed zaelgohary closed 1 month ago
We can add a MethodDecorator
which should validate object before trigger the targeted function
function TriggerValidate(): MethodDecorator {
return <T>(
target: object,
propertyKey: string | symbol,
descriptor: TypedPropertyDescriptor<T>,
): void | TypedPropertyDescriptor<T> => {
function value(...args: any[]): any {
const errors = validateSync(target);
if (errors.length > 0) {
console.log({ errors });
throw new Error("Something went wrong");
}
return target[propertyKey]?.(...args);
}
return {
...descriptor,
value: value as T,
};
};
}
which can be used like
class Zmount extends WorkloadData {
@TriggerValidate()
challenge(): string {
return ''
}
}
Work completed:
Implemented a way to validate class prop/methods when set/call.
verified compute capacity is now added to the gridclient tests module and ran the test and it is working fine
Is there an existing issue for this?
which package/s did you face the problem with?
grid_client
What happened?
No errors were thrown when testing with invalid min, max, empty values, and decimal values.
Steps To Reproduce
Run the following test: https://github.com/threefoldtech/tfgrid-sdk-ts/pull/2820/files
which network/s did you face the problem on?
Dev
version
Locally
Twin ID/s
No response
Node ID/s
No response
Farm ID/s
No response
Contract ID/s
No response
Relevant screenshots/screen records
-
Relevant log output