Last active
August 6, 2018 13:42
-
-
Save richthegeek/ffe78543c530f5bf20b3b7ae5d9d3350 to your computer and use it in GitHub Desktop.
This file contains 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
const Model = require('sequelize').Model; | |
class User extends Model { | |
columns: { | |
id: { | |
autoIncrement: true, | |
primaryKey: true, | |
type: Model.DataTypes.INTEGER(10) | |
}, | |
username: Model.DataTypes.STRING, | |
password: Model.DataTypes.STRING(40) | |
}, | |
underscored: true, | |
freezeTableName: true, | |
static checkUsernameExists (username) { | |
return User.count({where: {username}}); | |
} | |
set password (password) { | |
let hash = crypto.createHash('sha1').update(password).toString('hex'); | |
this.setDataValue('password', hash); | |
} | |
} | |
module.exports = (sequelizeInstance) => { | |
sequelizeInstance.importClass(User) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment