Forked from talyssonoc/sequelize-users-repository.js
Last active
November 10, 2018 07:07
-
-
Save leolana/a27d5e6b4f395504adec10353a9e9837 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
class SequelizeUsersRepository { | |
constructor({ userModel }) { | |
this.userModel = userModel; | |
} | |
add(user) { | |
const { valid, errors } = user.validate(); | |
if(!valid) { | |
const error = new Error('ValidationError'); | |
error.details = errors; | |
return Promise.reject(error); | |
} | |
return this.userModel | |
.create(user.attributes) | |
.then((dbUser) => dbUser.dataValues); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment