fcsc_ipi_backend/app/models/user.model.js
2025-12-30 16:48:14 +05:30

85 lines
1.8 KiB
JavaScript

module.exports = (sequelize, DataTypes) => {
const User = sequelize.define(
"admin_users",
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
allowNull: false,
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
password: {
type: DataTypes.STRING,
allowNull: false,
},
last_login: {
type: DataTypes.DATE,
allowNull: true,
},
reset_otp: {
type: DataTypes.STRING,
allowNull: true,
},
reset_otp_expires_at: {
type: DataTypes.DATE,
allowNull: true,
},
login_otp: {
type: DataTypes.STRING,
allowNull: true,
},
login_otp_expires_at: {
type: DataTypes.DATE,
allowNull: true,
},
is_active: {
type: DataTypes.BOOLEAN,
defaultValue: true,
},
},
{
defaultScope: {
attributes: {
exclude: [
"password",
"reset_otp",
"reset_otp_expires_at",
"login_otp",
"login_otp_expires_at",
],
},
},
// -------------------------------------------------------------
// 2. Special scope for login or OTP flows
// Use: User.scope("withSensitive").findOne(...)
// -------------------------------------------------------------
scopes: {
withSensitive: {
attributes: {
include: [
"password",
"reset_otp",
"reset_otp_expires_at",
"login_otp",
"login_otp_expires_at",
],
},
},
},
}
);
return User;
};