Skip to content

Instantly share code, notes, and snippets.

@beeman
Created May 27, 2018 04:54
Show Gist options
  • Save beeman/7db1a38245e6e124c54903524785ddde to your computer and use it in GitHub Desktop.
Save beeman/7db1a38245e6e124c54903524785ddde to your computer and use it in GitHub Desktop.
// THIS WORKS
@Validate()
async create(@Validator() profile: Profile): Promise<Profile> {
const profileInstance = plainToClass(Profile, {...profile, id: uuid()});
const errors = await validate(profileInstance);
if (errors.length > 0) {
throw new BadRequestException(errors);
}
this.profiles.push(profileInstance);
return profileInstance;
}
// THIS DOES NOT WORK
@Validate()
async create(@Validator() profile: Profile): Promise<Profile> {
const profileInstance = plainToClass(Profile, {...profile, id: uuid()});
const errors = await validate(profileInstance);
if (errors.length > 0) {
throw new BadRequestException(errors);
}
this.profiles.push(profileInstance);
return profileInstance;
}
// HOW I WOULD LOVE THAT IT WORKED
@Validate()
async create(@Validator() profile: Profile): Promise<Profile> {
this.profiles.push(profile);
return profile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment