From 7613a5f9b7c09be41dfb0463f381c35c7cda82e2 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Thu, 4 Dec 2025 17:45:29 +0530 Subject: [PATCH] GWM : removed password scope --- app/models/establishment_user.model.js | 40 +++++++++++--------------- app/models/user.model.js | 40 +++++++++++--------------- 2 files changed, 34 insertions(+), 46 deletions(-) diff --git a/app/models/establishment_user.model.js b/app/models/establishment_user.model.js index 99b2593..9426d17 100644 --- a/app/models/establishment_user.model.js +++ b/app/models/establishment_user.model.js @@ -65,30 +65,24 @@ module.exports = (sequelize, DataTypes) => { timestamps: false, tableName: "establishment_users", }, - { - // 1. EXCLUDE sensitive fields from all queries - defaultScope: { - attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] }, - }, + // { + // // 1. EXCLUDE sensitive fields from all queries + // defaultScope: { + // attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] }, + // }, - // 2. Ensure manual selections still hide sensitive fields - scopes: { - withSensitive: { - attributes: { include: ["password", "reset_otp", "reset_otp_expires_at"] }, - }, - }, - - // 3. Remove sensitive fields when converting to JSON - instanceMethods: { - toJSON() { - const values = { ...this.get() }; - delete values.password; - delete values.reset_otp; - delete values.reset_otp_expires_at; - return values; - }, - }, - } + // // ------------------------------------------------------------- + // // 2. Special scope for login or OTP flows + // // Use: User.scope("withSensitive").findOne(...) + // // ------------------------------------------------------------- + // scopes: { + // withSensitive: { + // attributes: { + // include: ["password", "reset_otp", "reset_otp_expires_at"], + // }, + // }, + // }, + // } ); EstablishmentUser.associate = (models) => { diff --git a/app/models/user.model.js b/app/models/user.model.js index e91a87d..46bfb24 100644 --- a/app/models/user.model.js +++ b/app/models/user.model.js @@ -35,30 +35,24 @@ module.exports = (sequelize, DataTypes) => { defaultValue: true, }, }, - { - // 1. EXCLUDE sensitive fields from all queries - defaultScope: { - attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] }, - }, + // { + // // 1. EXCLUDE sensitive fields from all queries + // defaultScope: { + // attributes: { exclude: ["password", "reset_otp", "reset_otp_expires_at"] }, + // }, - // 2. Ensure manual selections still hide sensitive fields - scopes: { - withSensitive: { - attributes: { include: ["password", "reset_otp", "reset_otp_expires_at"] }, - }, - }, - - // 3. Remove sensitive fields when converting to JSON - instanceMethods: { - toJSON() { - const values = { ...this.get() }; - delete values.password; - delete values.reset_otp; - delete values.reset_otp_expires_at; - return values; - }, - }, - } + // // ------------------------------------------------------------- + // // 2. Special scope for login or OTP flows + // // Use: User.scope("withSensitive").findOne(...) + // // ------------------------------------------------------------- + // scopes: { + // withSensitive: { + // attributes: { + // include: ["password", "reset_otp", "reset_otp_expires_at"], + // }, + // }, + // }, + // } ); return User;