abhishek-akbari01
add new fields in user modal
64ebbd0
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;