'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;
};