Skip to content

Instantly share code, notes, and snippets.

@talyssonoc
Created April 4, 2017 02:18
Show Gist options
  • Save talyssonoc/a27de58e3a78cfafd25fabca584a4ae9 to your computer and use it in GitHub Desktop.
Save talyssonoc/a27de58e3a78cfafd25fabca584a4ae9 to your computer and use it in GitHub Desktop.
const EventEmitter = require('events');
class CreateUser extends EventEmitter {
constructor({ usersRepository }) {
super();
this.usersRepository = usersRepository;
}
execute(userData) {
const user = new User(userData);
this.usersRepository
.add(user)
.then((newUser) => {
this.emit('SUCCESS', newUser);
})
.catch((error) => {
if(error.message === 'ValidationError') {
return this.emit('VALIDATION_ERROR', error);
}
this.emit('ERROR', error);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment