From 88d7617da50c47a5f40ac9955c4165c888ff0347 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 30 Dec 2025 16:48:14 +0530 Subject: [PATCH] module changes updated --- app/models/establishment_user.model.js | 41 ++++++++++++++++++++------ app/models/user.model.js | 38 +++++++++++++++++++----- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/app/models/establishment_user.model.js b/app/models/establishment_user.model.js index e6ee4fa..d05eba3 100644 --- a/app/models/establishment_user.model.js +++ b/app/models/establishment_user.model.js @@ -74,41 +74,64 @@ module.exports = (sequelize, DataTypes) => { allowNull: true, }, }, + { + login_otp: { + type: DataTypes.STRING, + allowNull: true, + }, + + login_otp_expires_at: { + type: DataTypes.DATE, + allowNull: true, + }, + }, { - // ============================================================ - // Model Options - // ============================================================ timestamps: false, tableName: "establishment_users", - // 1. Hide sensitive fields by default + // Hide sensitive fields by default defaultScope: { 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: { withSensitive: { 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 () { const values = { ...this.get() }; delete values.password; delete values.reset_otp; delete values.reset_otp_expires_at; + delete values.login_otp; + delete values.login_otp_expires_at; return values; }; - // Relationships + // ==================================================== + // Associations + // ==================================================== EstablishmentUser.associate = (models) => { EstablishmentUser.belongsTo(models.Establishment, { foreignKey: "establishment_id", diff --git a/app/models/user.model.js b/app/models/user.model.js index dc008b4..732de15 100644 --- a/app/models/user.model.js +++ b/app/models/user.model.js @@ -32,15 +32,32 @@ module.exports = (sequelize, DataTypes) => { 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, }, }, { - // 1. EXCLUDE sensitive fields from all queries - defaultScope: { - attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] }, + defaultScope: { + attributes: { + exclude: [ + "password", + "reset_otp", + "reset_otp_expires_at", + "login_otp", + "login_otp_expires_at", + ], + }, }, // ------------------------------------------------------------- @@ -50,13 +67,18 @@ module.exports = (sequelize, DataTypes) => { scopes: { withSensitive: { attributes: { - include: ["password", "reset_otp", "reset_otp_expires_at"], + include: [ + "password", + "reset_otp", + "reset_otp_expires_at", + "login_otp", + "login_otp_expires_at", + ], }, }, }, } ); - - return User; - }; - \ No newline at end of file + + return User; +};