Include complete API and frontend sources for unified deployment
This commit is contained in:
1 parent
627b0ae60e
commit
d8fcae32b0
93 files changed
+53270
-3
No files matched your search
@@ -0,0 +1,60 @@
|
||||
import sequelize from 'sequelize';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const { DataTypes, Model } = sequelize;
|
||||
|
||||
export default class User extends Model {
|
||||
static initialize(sequelize) {
|
||||
User.init(
|
||||
{
|
||||
id: { type: DataTypes.UUID, primaryKey: true },
|
||||
isAdmin: { type: DataTypes.BOOLEAN, defaultValue: false, allowNull: false },
|
||||
role: {
|
||||
type: DataTypes.STRING(20),
|
||||
defaultValue: 'expert',
|
||||
allowNull: false,
|
||||
validate: { isIn: [['expert', 'technical']] },
|
||||
},
|
||||
|
||||
login: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
unique: 'login',
|
||||
},
|
||||
password: {
|
||||
type: DataTypes.STRING,
|
||||
set(val) {
|
||||
this.setDataValue('password', bcrypt.hashSync(val, bcrypt.genSaltSync()));
|
||||
},
|
||||
},
|
||||
passwordForAdmin: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
iat: { type: DataTypes.BIGINT },
|
||||
sessionId: { type: DataTypes.UUID },
|
||||
|
||||
firstName: { type: DataTypes.STRING, allowNull: true, validate: { len: [1, 50] } },
|
||||
middleName: { type: DataTypes.STRING, allowNull: true, validate: { len: [0, 50] } },
|
||||
lastName: { type: DataTypes.STRING, allowNull: true, validate: { len: [1, 50] } },
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'User',
|
||||
tableName: 'users',
|
||||
}
|
||||
);
|
||||
|
||||
User.beforeCreate(user => {
|
||||
user.id = uuidv4();
|
||||
});
|
||||
}
|
||||
|
||||
fullName() {
|
||||
return this.firstName + ' ' + this.lastName;
|
||||
}
|
||||
|
||||
validatePassword(password) {
|
||||
return bcrypt.compareSync(password, this.password);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user