Skip to content

Instantly share code, notes, and snippets.

@richthegeek
Last active August 6, 2018 13:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richthegeek/ffe78543c530f5bf20b3b7ae5d9d3350 to your computer and use it in GitHub Desktop.
Save richthegeek/ffe78543c530f5bf20b3b7ae5d9d3350 to your computer and use it in GitHub Desktop.
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