diff --git a/client/src/pages/LandingPage.tsx b/client/src/pages/LandingPage.tsx index accf71a..abbb8bf 100644 --- a/client/src/pages/LandingPage.tsx +++ b/client/src/pages/LandingPage.tsx @@ -25,7 +25,7 @@ import { export default function LandingPage() { const [, setLocation] = useLocation(); - const { user } = useAuth(); + const { user } = useAuth() || {}; const { isListening, startListening, stopListening, isSupported } = useVoice(); const { theme } = useTheme(); diff --git a/server/storage.ts b/server/storage.ts index 7a91530..307c61e 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -166,13 +166,11 @@ export class DatabaseStorage implements IStorage { whereConditions.push(lte(financialRecords.date, endDate)); } - const query = db.select({ + const records = await db.select({ type: financialRecords.type, amount: financialRecords.amount }).from(financialRecords).where(and(...whereConditions)); - const records = await query; - let income = 0; let expenses = 0; @@ -234,17 +232,17 @@ export class DatabaseStorage implements IStorage { } async getAIInteractions(userId?: number, type?: string, limit: number = 50): Promise { - let query = db.select().from(aiInteractions); - const conditions = []; if (userId) conditions.push(eq(aiInteractions.userId, userId)); if (type) conditions.push(eq(aiInteractions.type, type)); - if (conditions.length > 0) { - query = query.where(and(...conditions)); - } + const baseQuery = db.select().from(aiInteractions); - return await query + const finalQuery = conditions.length > 0 + ? baseQuery.where(and(...conditions)) + : baseQuery; + + return await finalQuery .orderBy(desc(aiInteractions.createdAt)) .limit(limit); }