more ts and break apart big ass files
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Has been cancelled
Some checks failed
Deploy to Web Server flyer-crawler.projectium.com / deploy (push) Has been cancelled
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { pool } from './connection';
|
||||
import { logger } from '../logger';
|
||||
import { Profile, MasterGroceryItem, ShoppingList, ActivityLogItem } from '../../types';
|
||||
import { Profile, MasterGroceryItem, ShoppingList, ActivityLogItem, UserProfile, User } from '../../types';
|
||||
import { getShoppingLists } from './shopping';
|
||||
import { getWatchedItems } from './personalization';
|
||||
|
||||
@@ -384,35 +384,3 @@ export async function logSearchQuery(query: { userId?: string, queryText: string
|
||||
// Also a non-critical operation.
|
||||
}
|
||||
}
|
||||
|
||||
import { pool } from './connection';
|
||||
import { logger } from '../logger';
|
||||
import { UserProfile, Profile, User } from '../types';
|
||||
|
||||
// This file is assumed to exist and contain other database service functions.
|
||||
// The following function is added/updated to use the new SQL function.
|
||||
|
||||
/**
|
||||
* Retrieves a user's profile by their ID, combining data from the users and profiles tables.
|
||||
* @param userId The UUID of the user.
|
||||
* @returns A promise that resolves to the UserProfile object or null if not found.
|
||||
*/
|
||||
export async function findUserProfileById(userId: string): Promise<UserProfile | null> {
|
||||
try {
|
||||
const res = await pool.query<{
|
||||
id: string; email: string; full_name: string | null; avatar_url: string | null;
|
||||
preferences: any; role: 'admin' | 'user'; created_at: string; updated_at: string;
|
||||
}>('SELECT * FROM public.get_user_profile_by_id($1)', [userId]);
|
||||
|
||||
const row = res.rows[0];
|
||||
if (!row) return null;
|
||||
|
||||
// Map the flat SQL result to the nested UserProfile TypeScript type
|
||||
const user: User = { id: row.id, email: row.email };
|
||||
const profile: Profile = { id: row.id, full_name: row.full_name, avatar_url: row.avatar_url, preferences: row.preferences, role: row.role, created_at: row.created_at, updated_at: row.updated_at };
|
||||
return { ...profile, user };
|
||||
} catch (error) {
|
||||
logger.error('Database error in findUserProfileById:', { error, userId });
|
||||
throw new Error('Failed to retrieve user profile by ID.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user