Improve user experience and fix database queries for financial data
Fixes a bug when a user isn't logged in, and optimizes financial data retrieval and AI interaction queries. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 556aa286-edd2-4cea-8583-f4fc3cfd119b
This commit is contained in:
@@ -25,7 +25,7 @@ import {
|
|||||||
|
|
||||||
export default function LandingPage() {
|
export default function LandingPage() {
|
||||||
const [, setLocation] = useLocation();
|
const [, setLocation] = useLocation();
|
||||||
const { user } = useAuth();
|
const { user } = useAuth() || {};
|
||||||
const { isListening, startListening, stopListening, isSupported } = useVoice();
|
const { isListening, startListening, stopListening, isSupported } = useVoice();
|
||||||
const { theme } = useTheme();
|
const { theme } = useTheme();
|
||||||
|
|
||||||
|
|||||||
+7
-9
@@ -166,13 +166,11 @@ export class DatabaseStorage implements IStorage {
|
|||||||
whereConditions.push(lte(financialRecords.date, endDate));
|
whereConditions.push(lte(financialRecords.date, endDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = db.select({
|
const records = await db.select({
|
||||||
type: financialRecords.type,
|
type: financialRecords.type,
|
||||||
amount: financialRecords.amount
|
amount: financialRecords.amount
|
||||||
}).from(financialRecords).where(and(...whereConditions));
|
}).from(financialRecords).where(and(...whereConditions));
|
||||||
|
|
||||||
const records = await query;
|
|
||||||
|
|
||||||
let income = 0;
|
let income = 0;
|
||||||
let expenses = 0;
|
let expenses = 0;
|
||||||
|
|
||||||
@@ -234,17 +232,17 @@ export class DatabaseStorage implements IStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getAIInteractions(userId?: number, type?: string, limit: number = 50): Promise<AIInteraction[]> {
|
async getAIInteractions(userId?: number, type?: string, limit: number = 50): Promise<AIInteraction[]> {
|
||||||
let query = db.select().from(aiInteractions);
|
|
||||||
|
|
||||||
const conditions = [];
|
const conditions = [];
|
||||||
if (userId) conditions.push(eq(aiInteractions.userId, userId));
|
if (userId) conditions.push(eq(aiInteractions.userId, userId));
|
||||||
if (type) conditions.push(eq(aiInteractions.type, type));
|
if (type) conditions.push(eq(aiInteractions.type, type));
|
||||||
|
|
||||||
if (conditions.length > 0) {
|
const baseQuery = db.select().from(aiInteractions);
|
||||||
query = query.where(and(...conditions));
|
|
||||||
}
|
|
||||||
|
|
||||||
return await query
|
const finalQuery = conditions.length > 0
|
||||||
|
? baseQuery.where(and(...conditions))
|
||||||
|
: baseQuery;
|
||||||
|
|
||||||
|
return await finalQuery
|
||||||
.orderBy(desc(aiInteractions.createdAt))
|
.orderBy(desc(aiInteractions.createdAt))
|
||||||
.limit(limit);
|
.limit(limit);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user