Last active
August 12, 2019 07:32
-
-
Save darksh3ll/71b0f94f554a81f3164572b107bd1a2c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'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