Created
May 27, 2018 04:54
-
-
Save beeman/7db1a38245e6e124c54903524785ddde to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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