Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new ValidatePromise decorator - resolve promise before validate #369

Merged
merged 4 commits into from
Jul 24, 2019

Conversation

queses
Copy link
Contributor

@queses queses commented Jun 17, 2019

Added new @ValidatePromise decorator to mark property as Promise that should to be resolved before validation.

Tests for new decorator lays in promise-validation.spec.ts.

Example of use:

class MySubClass {
  @MinLength(5)
  name: string;
}

class MyClass {
    @ValidatePromise() @ValidateNested()
    mySubClass: Promise<MySubClass>;
}

const model = new MyClass();
const mySubClass = new MySubClass();
mySubClass.name = "my";
model.mySubClass = Promise.resolve(mySubClass);

const errors = await validator.validate(model)
errors.length.should.be.equal(1);

errors[1].target.should.be.equal(model);
errors[1].property.should.be.equal("mySubClass");
errors[1].value.should.be.equal(await model.mySubClass);
expect(errors[1].constraints).to.be.undefined;

@queses
Copy link
Contributor Author

queses commented Jun 17, 2019

Node v12 CI tests failed while v10 tests passed. Looks like library internal error.

@queses
Copy link
Contributor Author

queses commented Jun 17, 2019

Also looks like I forgot to increase version in package.json.

@vlapo
Copy link
Contributor

vlapo commented Jul 15, 2019

@queses could you please rebase? Tests should be fixed in latest commit.

@queses
Copy link
Contributor Author

queses commented Jul 17, 2019

Yup, it's OK now

@vlapo vlapo changed the title Promise validation added feat: new ValidatePromise decorator - resolve promise before validate Jul 21, 2019
@vlapo vlapo merged commit 35ec04d into typestack:master Jul 24, 2019
@vlapo
Copy link
Contributor

vlapo commented Jul 26, 2019

Thank you! :)

@vlapo vlapo added this to the v0.10.0 milestone Jul 26, 2019
@github-actions
Copy link

github-actions bot commented Aug 4, 2020

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants