module changes updated
This commit is contained in:
parent
b904b18355
commit
88d7617da5
@ -75,40 +75,63 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// ============================================================
|
login_otp: {
|
||||||
// Model Options
|
type: DataTypes.STRING,
|
||||||
// ============================================================
|
allowNull: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
login_otp_expires_at: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
timestamps: false,
|
timestamps: false,
|
||||||
tableName: "establishment_users",
|
tableName: "establishment_users",
|
||||||
|
|
||||||
// 1. Hide sensitive fields by default
|
// Hide sensitive fields by default
|
||||||
defaultScope: {
|
defaultScope: {
|
||||||
attributes: {
|
attributes: {
|
||||||
exclude: ["password", "reset_otp", "reset_otp_expires_at"],
|
exclude: [
|
||||||
|
"password",
|
||||||
|
"reset_otp",
|
||||||
|
"reset_otp_expires_at",
|
||||||
|
"login_otp",
|
||||||
|
"login_otp_expires_at",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// 2. Scope for login / sensitive queries
|
// Scope for login & sensitive operations
|
||||||
scopes: {
|
scopes: {
|
||||||
withSensitive: {
|
withSensitive: {
|
||||||
attributes: {
|
attributes: {
|
||||||
include: ["password", "reset_otp", "reset_otp_expires_at"],
|
include: [
|
||||||
|
"password",
|
||||||
|
"reset_otp",
|
||||||
|
"reset_otp_expires_at",
|
||||||
|
"login_otp",
|
||||||
|
"login_otp_expires_at",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// 3. Remove sensitive fields from all API responses
|
|
||||||
EstablishmentUser.prototype.toJSON = function () {
|
EstablishmentUser.prototype.toJSON = function () {
|
||||||
const values = { ...this.get() };
|
const values = { ...this.get() };
|
||||||
delete values.password;
|
delete values.password;
|
||||||
delete values.reset_otp;
|
delete values.reset_otp;
|
||||||
delete values.reset_otp_expires_at;
|
delete values.reset_otp_expires_at;
|
||||||
|
delete values.login_otp;
|
||||||
|
delete values.login_otp_expires_at;
|
||||||
return values;
|
return values;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Relationships
|
// ====================================================
|
||||||
|
// Associations
|
||||||
|
// ====================================================
|
||||||
EstablishmentUser.associate = (models) => {
|
EstablishmentUser.associate = (models) => {
|
||||||
EstablishmentUser.belongsTo(models.Establishment, {
|
EstablishmentUser.belongsTo(models.Establishment, {
|
||||||
foreignKey: "establishment_id",
|
foreignKey: "establishment_id",
|
||||||
|
|||||||
@ -32,15 +32,32 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
type: DataTypes.DATE,
|
type: DataTypes.DATE,
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
},
|
},
|
||||||
|
login_otp: {
|
||||||
|
type: DataTypes.STRING,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
|
||||||
|
login_otp_expires_at: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
|
||||||
is_active: {
|
is_active: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
defaultValue: true,
|
defaultValue: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// 1. EXCLUDE sensitive fields from all queries
|
|
||||||
defaultScope: {
|
defaultScope: {
|
||||||
attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] },
|
attributes: {
|
||||||
|
exclude: [
|
||||||
|
"password",
|
||||||
|
"reset_otp",
|
||||||
|
"reset_otp_expires_at",
|
||||||
|
"login_otp",
|
||||||
|
"login_otp_expires_at",
|
||||||
|
],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
@ -50,7 +67,13 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
scopes: {
|
scopes: {
|
||||||
withSensitive: {
|
withSensitive: {
|
||||||
attributes: {
|
attributes: {
|
||||||
include: ["password", "reset_otp", "reset_otp_expires_at"],
|
include: [
|
||||||
|
"password",
|
||||||
|
"reset_otp",
|
||||||
|
"reset_otp_expires_at",
|
||||||
|
"login_otp",
|
||||||
|
"login_otp_expires_at",
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -59,4 +82,3 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
|
|
||||||
return User;
|
return User;
|
||||||
};
|
};
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user