diff --git a/server/src/routes/stats.ts b/server/src/routes/stats.ts index 3258151..30edc60 100644 --- a/server/src/routes/stats.ts +++ b/server/src/routes/stats.ts @@ -72,16 +72,27 @@ router.get('/overview', async (req: AuthRequest, res: Response) => { `SELECT COALESCE(SUM(CASE WHEN t.type = 'expense' THEN t.amount ELSE 0 END), 0) as expense, COALESCE(SUM(CASE WHEN t.type = 'income' THEN t.amount ELSE 0 END), 0) as income, - COUNT(*) as count + COUNT(*) as count, + SUM(CASE WHEN t.type = 'expense' THEN 1 ELSE 0 END) as expenseCount, + SUM(CASE WHEN t.type = 'income' THEN 1 ELSE 0 END) as incomeCount FROM transactions t ${result.where}`, [...result.params, startDate, endDate] ) const row = (rows as any[])[0] const daily = elapsedDays > 0 ? Math.round(row.expense / elapsedDays) : 0 + const dailyIncome = elapsedDays > 0 ? Math.round(row.income / elapsedDays) : 0 res.json({ code: 0, - data: { expense: row.expense, income: row.income, count: row.count, daily } + data: { + expense: row.expense, + income: row.income, + count: row.count, + daily, + dailyIncome, + expenseCount: row.expenseCount, + incomeCount: row.incomeCount + } }) } catch (err) { console.error('[Stats] overview error:', err)