fix tests ugh
All checks were successful
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Successful in 4m59s

This commit is contained in:
2025-12-09 17:06:43 -08:00
parent 3a66f31d55
commit 6354189d5c
10 changed files with 473 additions and 314 deletions

View File

@@ -11,7 +11,7 @@ import { PersonalizationRepository } from './personalization.db';
* Defines the structure of a user object as returned from the database.
*/
interface DbUser {
user_id: string; // UUID
user_id: string;
email: string;
// The password_hash can be null for users who signed up via OAuth.
password_hash: string | null;
@@ -110,6 +110,29 @@ export class UserRepository {
}
}
/**
* Finds a user by their email and joins their profile data.
* This is used by the LocalStrategy to get all necessary data for authentication and session creation in one query.
* @param email The email of the user to find.
* @returns A promise that resolves to the combined user and profile object or undefined if not found.
*/
async findUserWithProfileByEmail(email: string): Promise<(DbUser & Profile) | undefined> {
logger.debug(`[DB findUserWithProfileByEmail] Searching for user with email: ${email}`);
try {
const query = `
SELECT u.*, p.full_name, p.avatar_url, p.role, p.points, p.preferences, p.address_id
FROM public.users u
JOIN public.profiles p ON u.user_id = p.user_id
WHERE u.email = $1;
`;
const res = await this.db.query<(DbUser & Profile)>(query, [email]);
return res.rows[0];
} catch (error) {
logger.error('Database error in findUserWithProfileByEmail:', { error });
throw new Error('Failed to retrieve user with profile from database.');
}
}
/**
* Finds a user by their ID. Used by the JWT strategy to validate tokens.
* @param id The UUID of the user to find.