Compare commits

..

4 Commits

7 changed files with 51 additions and 21 deletions

View File

@@ -1,10 +1,16 @@
# Changelog # Changelog
## [Frontend 0.11.0 / Backend 0.10.0 / Shared 0.5.0] - 2026-08-21 ## [Frontend 0.11.1] - 2026-08-21
### Added ### Fixed
- Added category filtering to analytics summary and category breakdown, including savings-account interest handling in the filtered results. - Preserve the explicit «Без категории» analytics filter value when requesting data.
## [Frontend 0.11.0 / Backend 0.10.1 / Shared 0.5.0] - 2026-08-21
### Fixed
- Corrected analytics period boundaries for partial week/month ranges and added a usable «Без категории» filter with SQL coverage.
## [Backend 0.9.2] - 2026-08-20 ## [Backend 0.9.2] - 2026-08-20

View File

@@ -1,6 +1,6 @@
{ {
"name": "@family-budget/backend", "name": "@family-budget/backend",
"version": "0.10.0", "version": "0.10.1",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "tsx watch src/app.ts", "dev": "tsx watch src/app.ts",

View File

@@ -18,7 +18,7 @@ router.get(
from: from as string, from: from as string,
to: to as string, to: to as string,
accountId: accountId ? Number(accountId) : undefined, accountId: accountId ? Number(accountId) : undefined,
categoryId: categoryId ? Number(categoryId) : undefined, categoryId: categoryId !== undefined ? Number(categoryId) : undefined,
onlyConfirmed: onlyConfirmed === 'true', onlyConfirmed: onlyConfirmed === 'true',
}); });
res.json(result); res.json(result);
@@ -38,7 +38,7 @@ router.get(
from: from as string, from: from as string,
to: to as string, to: to as string,
accountId: accountId ? Number(accountId) : undefined, accountId: accountId ? Number(accountId) : undefined,
categoryId: categoryId ? Number(categoryId) : undefined, categoryId: categoryId !== undefined ? Number(categoryId) : undefined,
onlyConfirmed: onlyConfirmed === 'true', onlyConfirmed: onlyConfirmed === 'true',
}); });
res.json(result); res.json(result);
@@ -64,7 +64,7 @@ router.get(
from: from as string, from: from as string,
to: to as string, to: to as string,
accountId: accountId ? Number(accountId) : undefined, accountId: accountId ? Number(accountId) : undefined,
categoryId: categoryId ? Number(categoryId) : undefined, categoryId: categoryId !== undefined ? Number(categoryId) : undefined,
onlyConfirmed: onlyConfirmed === 'true', onlyConfirmed: onlyConfirmed === 'true',
granularity: granularity as Granularity, granularity: granularity as Granularity,
}); });

View File

@@ -28,17 +28,33 @@ async function testQueries(): Promise<void> {
); );
await insert(otherAccountId, '2026-07-01T12:00:00+03:00', -99_000, categoryId.expense, 'analytics-test-6'); await insert(otherAccountId, '2026-07-01T12:00:00+03:00', -99_000, categoryId.expense, 'analytics-test-6');
await insert(accountId, '2026-08-01T12:00:00+03:00', -7_000, categoryId.expense, 'analytics-test-7'); await insert(accountId, '2026-08-01T12:00:00+03:00', -7_000, categoryId.expense, 'analytics-test-7');
await client.query(
"INSERT INTO transactions (account_id, operation_at, amount_signed, commission, description, direction, fingerprint, category_id, is_category_confirmed) VALUES ($1, '2026-07-07T12:00:00+03:00', -2_500, 0, 'uncategorized', 'expense', 'analytics-test-uncategorized', NULL, FALSE)",
[accountId],
);
const params = { from: '2026-07-01', to: '2026-07-31', accountId, onlyConfirmed: true }; const params = { from: '2026-07-01', to: '2026-07-31', accountId, onlyConfirmed: true };
const summary = await getSummary(params, client); const summary = await getSummary(params, client);
assert.deepEqual({ expense: summary.totalExpense, income: summary.totalIncome, net: summary.net, transferOut: summary.transferOutflow, interest: summary.interestIncome }, { expense: 6_000, income: 15_000, net: 9_000, transferOut: 3_000, interest: 1_500 }); assert.deepEqual({ expense: summary.totalExpense, income: summary.totalIncome, net: summary.net, transferOut: summary.transferOutflow, interest: summary.interestIncome }, { expense: 6_000, income: 15_000, net: 9_000, transferOut: 3_000, interest: 1_500 });
const categorySummary = await getSummary({ ...params, categoryId: categoryId.expense }, client); const categorySummary = await getSummary({ ...params, categoryId: categoryId.expense }, client);
assert.deepEqual({ expense: categorySummary.totalExpense, income: categorySummary.totalIncome }, { expense: 6_000, income: 0 }); assert.deepEqual({ expense: categorySummary.totalExpense, income: categorySummary.totalIncome }, { expense: 6_000, income: 0 });
const uncategorized = await getSummary({ ...params, categoryId: 0, onlyConfirmed: false }, client);
assert.equal(uncategorized.totalExpense, 2_500);
assert.equal((await getSummary({ ...params, categoryId: 0, onlyConfirmed: true }, client)).totalExpense, 0);
assert.deepEqual((await getByCategory({ ...params, categoryId: 0, onlyConfirmed: false }, client)).map((item) => item.amount), [2_500]);
assert.deepEqual((await getByCategory({ ...params, categoryId: 0, onlyConfirmed: true }, client)), []);
assert.equal((await getSummary({ ...params, from: '2026-08-01', to: '2026-08-31' }, client)).totalExpense, 7_000); assert.equal((await getSummary({ ...params, from: '2026-08-01', to: '2026-08-31' }, client)).totalExpense, 7_000);
assert.deepEqual((await getByCategory(params, client)).map((item) => item.amount), [6_000]); assert.deepEqual((await getByCategory(params, client)).map((item) => item.amount), [6_000]);
const timeseries = await getTimeseries({ ...params, granularity: 'month' }, client); const timeseries = await getTimeseries({ ...params, granularity: 'month' }, client);
assert.equal(timeseries[0].expenseAmount, 6_000); assert.equal(timeseries[0].expenseAmount, 6_000);
assert.equal(timeseries[0].incomeAmount, 15_000); assert.equal(timeseries[0].incomeAmount, 15_000);
const partial = await getTimeseries({ ...params, from: '2026-07-02', to: '2026-07-03', granularity: 'month' }, client);
assert.equal(partial[0].expenseAmount, 0);
assert.equal(partial[0].incomeAmount, 20_000);
const uncategorizedSeries = await getTimeseries({ ...params, categoryId: 0, onlyConfirmed: false, granularity: 'month' }, client);
assert.equal(uncategorizedSeries[0].expenseAmount, 2_500);
const confirmedUncategorizedSeries = await getTimeseries({ ...params, categoryId: 0, onlyConfirmed: true, granularity: 'month' }, client);
assert.equal(confirmedUncategorizedSeries[0].expenseAmount, 0);
} finally { } finally {
await client.query('ROLLBACK'); await client.query('ROLLBACK');
client.release(); client.release();

View File

@@ -63,9 +63,11 @@ function buildBaseConditions(
idx++; idx++;
} }
if (params.categoryId != null) { if (params.categoryId != null) {
conditions.push(`t.category_id = $${idx}`); conditions.push(params.categoryId === 0 ? 't.category_id IS NULL' : `t.category_id = $${idx}`);
values.push(params.categoryId); if (params.categoryId !== 0) {
idx++; values.push(params.categoryId);
idx++;
}
} }
if (params.onlyConfirmed) { if (params.onlyConfirmed) {
conditions.push('t.is_category_confirmed = TRUE'); conditions.push('t.is_category_confirmed = TRUE');
@@ -202,6 +204,8 @@ export async function getTimeseries(
} }
const txConditions: string[] = [ const txConditions: string[] = [
't.operation_at::date >= $1::date',
't.operation_at::date <= $2::date',
't.operation_at::date >= p.period_start', 't.operation_at::date >= p.period_start',
't.operation_at::date <= p.period_end', 't.operation_at::date <= p.period_end',
]; ];
@@ -213,8 +217,11 @@ export async function getTimeseries(
values.push(params.accountId); values.push(params.accountId);
} }
if (params.categoryId != null) { if (params.categoryId != null) {
txConditions.push(`t.category_id = $${idx++}`); if (params.categoryId === 0) txConditions.push('t.category_id IS NULL');
values.push(params.categoryId); else {
txConditions.push(`t.category_id = $${idx++}`);
values.push(params.categoryId);
}
} }
if (params.onlyConfirmed) { if (params.onlyConfirmed) {
txConditions.push('t.is_category_confirmed = TRUE'); txConditions.push('t.is_category_confirmed = TRUE');

View File

@@ -1,6 +1,6 @@
{ {
"name": "@family-budget/frontend", "name": "@family-budget/frontend",
"version": "0.11.0", "version": "0.11.1",
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {

View File

@@ -68,7 +68,7 @@ export function AnalyticsPage() {
from: period.from, from: period.from,
to: period.to, to: period.to,
...(accountId ? { accountId: Number(accountId) } : {}), ...(accountId ? { accountId: Number(accountId) } : {}),
...(categoryId ? { categoryId: Number(categoryId) } : {}), ...(categoryId !== '' ? { categoryId: Number(categoryId) } : {}),
...(onlyConfirmed ? { onlyConfirmed: true } : {}), ...(onlyConfirmed ? { onlyConfirmed: true } : {}),
}; };
@@ -118,13 +118,6 @@ export function AnalyticsPage() {
))} ))}
</select> </select>
</div> </div>
<div className="field">
<label className="field__label">Категория</label>
<select value={categoryId} onChange={(e) => setCategoryId(e.target.value)}>
<option value="">Все категории</option>
{categories.map((c) => <option key={c.id} value={c.id}>{c.name}</option>)}
</select>
</div>
<div className="field field--checkbox"> <div className="field field--checkbox">
<label className="field__label field__label--checkbox"> <label className="field__label field__label--checkbox">
<input <input
@@ -135,6 +128,14 @@ export function AnalyticsPage() {
Только подтверждённые Только подтверждённые
</label> </label>
</div> </div>
<div className="field">
<label className="field__label">Категория</label>
<select value={categoryId} onChange={(e) => setCategoryId(e.target.value)}>
<option value="">Все категории</option>
<option value="0">Без категории</option>
{categories.map((c) => <option key={c.id} value={c.id}>{c.name}</option>)}
</select>
</div>
</div> </div>
</div> </div>