Spaces:
Runtime error
Runtime error
File size: 1,740 Bytes
049adb8 1f6a8f9 049adb8 6f05a9e 049adb8 fce755d 049adb8 099ffb7 64ebbd0 049adb8 099ffb7 64ebbd0 049adb8 e30c136 fa64d80 049adb8 1056391 049adb8 6f05a9e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
import {
DataTypes,
Model,
InferAttributes,
InferCreationAttributes,
CreationOptional,
} from 'sequelize';
import { sequelize } from './index';
import Role from './roles';
import { UserInterface } from '../shared/interfaces/user.interface';
class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> implements UserInterface {
declare id: CreationOptional<number>;
declare name: string;
declare email: string;
declare role_id: number;
declare status: string;
declare password: string;
declare reset_token: CreationOptional<string | null>;
declare reset_token_expiry: CreationOptional<Date | null>;
}
User.init(
{
id: {
type: DataTypes.INTEGER.UNSIGNED,
autoIncrement: true,
primaryKey: true,
unique: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
},
role_id: {
type: DataTypes.INTEGER.UNSIGNED,
allowNull: false,
references: {
model: Role,
key: 'id',
},
},
status: {
type: DataTypes.STRING,
allowNull: false,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
reset_token: {
type: DataTypes.STRING,
allowNull: true,
},
reset_token_expiry: {
type: DataTypes.DATE,
allowNull: true,
},
},
{
sequelize,
tableName: 'users',
underscored: true,
freezeTableName: true,
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: true,
deletedAt: 'deleted_at',
}
);
User.belongsTo(Role, { foreignKey: 'role_id', as : 'role' });
export default User;
|