fix: Transactions открывался на январе вместо текущего месяца

parseMonthParam передавал Number(null) дальше — а это 0, не NaN, поэтому
проверка "отсутствует/невалиден -> fallback" не срабатывала и месяц
зажимался в 1. Добавил явную проверку value === null и диапазон 1-12
вместо клампинга (тот же фикс для parseYearParam для единообразия).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
ZProger
2026-08-17 02:39:17 +03:00
parent bbbd67bc72
commit b9ff3ab404
2 changed files with 8 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "aurum-frontend", "name": "aurum-frontend",
"private": true, "private": true,
"version": "0.20.1", "version": "0.20.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -17,14 +17,18 @@ import type { Transaction, TransactionType } from "@/types";
const PAGE_SIZE = 20; const PAGE_SIZE = 20;
/** Clamp a query-param month to 1-12, falling back to `fallback` for /** Parses a query-param month, falling back to `fallback` for anything
* anything missing or out of range (e.g. a hand-edited URL). */ * missing or out of range (e.g. a hand-edited URL). Must check `value`
* for null before `Number()` — `Number(null)` is 0, not NaN, so a missing
* param would otherwise silently pass the integer check and clamp to 1. */
function parseMonthParam(value: string | null, fallback: number): number { function parseMonthParam(value: string | null, fallback: number): number {
if (value === null) return fallback;
const parsed = Number(value); const parsed = Number(value);
return Number.isInteger(parsed) ? Math.min(12, Math.max(1, parsed)) : fallback; return Number.isInteger(parsed) && parsed >= 1 && parsed <= 12 ? parsed : fallback;
} }
function parseYearParam(value: string | null, fallback: number): number { function parseYearParam(value: string | null, fallback: number): number {
if (value === null) return fallback;
const parsed = Number(value); const parsed = Number(value);
return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback; return Number.isInteger(parsed) && parsed > 0 ? parsed : fallback;
} }