Last active
April 17, 2026 14:26
-
-
Save s3rgeym/ebd5ac8fbd1d042ad1b4926a042d9666 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'; | |
| import Sequelize from 'sequelize'; | |
| import bcrypt from 'bcryptjs'; | |
| export default class User extends Sequelize.Model { | |
| static init(sequelize) { | |
| return super.init({ | |
| username: { | |
| type: Sequelize.STRING, | |
| unique: true, | |
| allowNull: false | |
| }, | |
| password: { | |
| type: Sequelize.STRING, | |
| allowNull: false, | |
| validate: { | |
| notEmpty: { msg: 'Password can\'t be empty' } | |
| }, | |
| set(value) { | |
| this.setDataValue('password', bcrypt.hashSync(value, 10)); | |
| } | |
| }, | |
| userCategoryId: { | |
| type: Sequelize.INTEGER, | |
| references: { | |
| model: sequelize.models.UserCategory, | |
| key: 'id' | |
| } | |
| }, | |
| email: { | |
| type: Sequelize.STRING, | |
| unique: true, | |
| allowNull: false, | |
| validate: { | |
| isEmail: { msg: 'Please provide valid e-mail address' } | |
| } | |
| } | |
| }, { | |
| sequelize: sequelize, | |
| tableName: 'users', | |
| timestamps: true, | |
| paranoid: true | |
| }); | |
| } | |
| static associate(models) { | |
| this.belongsTo(models.UserCategory, { foreignKey: 'userCategoryId' }); | |
| } | |
| } |
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
| const Sequelize = require('sequlize') | |
| class User extends Sequlize.Model { | |
| static init(sequelize) { | |
| return super.init({ | |
| id: { | |
| type: Sequelize.INTEGER, | |
| primaryKey: true, | |
| autoIncrement: true, | |
| }, | |
| }, { | |
| sequelize, | |
| tableName: 'users', | |
| schema: 'app' | |
| }) | |
| } | |
| } | |
| module.exports = { | |
| User, | |
| } |
s3rgeym
commented
May 6, 2019
Author


Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment