From 1d35aa98d925ba4e74d9962e77a7b4b661990743 Mon Sep 17 00:00:00 2001 From: Sakariyah Abdulhazeem Date: Wed, 2 Sep 2026 16:16:34 +0100 Subject: [PATCH] perf: harden User profile repository lookups --- src/models/User.model.ts | 6 ++++++ src/services/auth.service.ts | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/models/User.model.ts b/src/models/User.model.ts index 8d86163..5ac3531 100644 --- a/src/models/User.model.ts +++ b/src/models/User.model.ts @@ -21,6 +21,12 @@ const USER_VALIDATION_CONSTRAINTS = Object.freeze({ EMAIL_PATTERN: /^[^\s@]+@[^\s@]+\.[^\s@]+$/, }); +/** Columns used by profile lookups; relations are loaded explicitly by callers that need them. */ +export const USER_PROFILE_SELECT = [ + "id", "stellarAddress", "email", "userType", "kycStatus", + "isKycVerified", "createdAt", "updatedAt", "deletedAt", +] as const; + @Entity("users") @Index("idx_users_user_type_kyc_status", ["userType", "kycStatus"]) export class User { diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index 21fdf0a..43644ee 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -4,7 +4,7 @@ import { DataSource, IsNull, Repository } from "typeorm"; import { Keypair, StrKey } from "stellar-sdk"; import type { AppConfig } from "../config/env"; import { AuthChallenge } from "../models/AuthChallenge.model"; -import { User } from "../models/User.model"; +import { User, USER_PROFILE_SELECT } from "../models/User.model"; import type { PublicUser } from "../types/auth"; import { HttpError } from "../utils/http-error"; import { @@ -363,12 +363,14 @@ class TypeOrmUserRepository implements UserRepositoryContract { findById(id: string): Promise { return this.repository.findOne({ where: { id }, + select: USER_PROFILE_SELECT, }); } findByStellarAddress(stellarAddress: string): Promise { return this.repository.findOne({ where: { stellarAddress }, + select: USER_PROFILE_SELECT, }); }