Add exclude_virtual parameter to match backend API

Adds support for the new exclude_virtual parameter added to the Castle backend API.

Changes:
- Added excludeVirtual parameter to getAccounts() (defaults to true)
- Added excludeVirtual parameter to getAccountHierarchy() (defaults to true)
- Both methods now pass the parameter to the backend API

This ensures virtual parent accounts are excluded from user views by default,
while still allowing permission inheritance to work correctly on the backend.

The default value of true means existing code automatically benefits from
the change without modification - virtual accounts won't appear in user
account selectors.

🤖 Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
padreug 2025-11-11 03:29:36 +01:00
parent f5075ed96d
commit 78fba2a637

View file

@ -49,13 +49,21 @@ export class ExpensesAPI extends BaseService {
*
* @param walletKey - Wallet key for authentication
* @param filterByUser - If true, only return accounts the user has permissions for
* @param excludeVirtual - If true, exclude virtual parent accounts (default true for user views)
*/
async getAccounts(walletKey: string, filterByUser: boolean = false): Promise<Account[]> {
async getAccounts(
walletKey: string,
filterByUser: boolean = false,
excludeVirtual: boolean = true
): Promise<Account[]> {
try {
const url = new URL(`${this.baseUrl}/castle/api/v1/accounts`)
if (filterByUser) {
url.searchParams.set('filter_by_user', 'true')
}
if (excludeVirtual) {
url.searchParams.set('exclude_virtual', 'true')
}
const response = await fetch(url.toString(), {
method: 'GET',
@ -84,13 +92,15 @@ export class ExpensesAPI extends BaseService {
* @param walletKey - Wallet key for authentication
* @param rootAccount - Optional root account to filter by (e.g., "Expenses")
* @param filterByUser - If true, only return accounts the user has permissions for
* @param excludeVirtual - If true, exclude virtual parent accounts (default true for user views)
*/
async getAccountHierarchy(
walletKey: string,
rootAccount?: string,
filterByUser: boolean = false
filterByUser: boolean = false,
excludeVirtual: boolean = true
): Promise<AccountNode[]> {
const accounts = await this.getAccounts(walletKey, filterByUser)
const accounts = await this.getAccounts(walletKey, filterByUser, excludeVirtual)
// Filter by root account if specified
let filteredAccounts = accounts