( key: keyof TransactionFilters, value: unknown )
| 71 | } |
| 72 | |
| 73 | export function validateFilterValue( |
| 74 | key: keyof TransactionFilters, |
| 75 | value: unknown |
| 76 | ): boolean { |
| 77 | switch (key) { |
| 78 | case "status": |
| 79 | return [ |
| 80 | "RECONCILED", |
| 81 | "NEEDS_CATEGORIZATION", |
| 82 | "NEEDS_REVIEW", |
| 83 | "IN_PROGRESS", |
| 84 | ].includes(value); |
| 85 | case "type": |
| 86 | return ["INCOME", "EXPENSE", "TRANSFER"].includes(value); |
| 87 | case "startDate": |
| 88 | case "endDate": |
| 89 | return value instanceof Date && !isNaN(value.getTime()); |
| 90 | case "search": |
| 91 | case "accountId": |
| 92 | case "categoryId": |
| 93 | return typeof value === "string"; |
| 94 | default: |
| 95 | return true; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | export function countActiveFilters(filters: TransactionFilters): number { |
| 100 | return Object.values(filters).filter((value) => { |
no outgoing calls
no test coverage detected