Skip to content

Instantly share code, notes, and snippets.

@darksh3ll
Last active August 12, 2019 07:32
Show Gist options
  • Save darksh3ll/71b0f94f554a81f3164572b107bd1a2c to your computer and use it in GitHub Desktop.
Save darksh3ll/71b0f94f554a81f3164572b107bd1a2c to your computer and use it in GitHub Desktop.
'use strict';
const bcrypt = require('bcrypt');
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
firstname: DataTypes.STRING,
lastname: DataTypes.STRING,
email:{
type:DataTypes.STRING,
validate:{
isEmail:true
}
},
username: DataTypes.STRING,
password: DataTypes.STRING,
isAdmin: DataTypes.BOOLEAN,
isConnected: DataTypes.BOOLEAN
}, {
hooks:{
beforeCreate: (user) => {
return bcrypt.hash(user.password,10)
.then((hash) => user.password = hash)
.catch((err) => console.log(err))
}
}
});
User.associate = function(models) {
// associations can be defined here
};
return User;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment