Skip to content

Instantly share code, notes, and snippets.

@leolana
Forked from talyssonoc/sequelize-users-repository.js
Last active November 10, 2018 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leolana/a27d5e6b4f395504adec10353a9e9837 to your computer and use it in GitHub Desktop.
Save leolana/a27d5e6b4f395504adec10353a9e9837 to your computer and use it in GitHub Desktop.
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