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:
parent
f5075ed96d
commit
78fba2a637
1 changed files with 13 additions and 3 deletions
|
|
@ -49,13 +49,21 @@ export class ExpensesAPI extends BaseService {
|
||||||
*
|
*
|
||||||
* @param walletKey - Wallet key for authentication
|
* @param walletKey - Wallet key for authentication
|
||||||
* @param filterByUser - If true, only return accounts the user has permissions for
|
* @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 {
|
try {
|
||||||
const url = new URL(`${this.baseUrl}/castle/api/v1/accounts`)
|
const url = new URL(`${this.baseUrl}/castle/api/v1/accounts`)
|
||||||
if (filterByUser) {
|
if (filterByUser) {
|
||||||
url.searchParams.set('filter_by_user', 'true')
|
url.searchParams.set('filter_by_user', 'true')
|
||||||
}
|
}
|
||||||
|
if (excludeVirtual) {
|
||||||
|
url.searchParams.set('exclude_virtual', 'true')
|
||||||
|
}
|
||||||
|
|
||||||
const response = await fetch(url.toString(), {
|
const response = await fetch(url.toString(), {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|
@ -84,13 +92,15 @@ export class ExpensesAPI extends BaseService {
|
||||||
* @param walletKey - Wallet key for authentication
|
* @param walletKey - Wallet key for authentication
|
||||||
* @param rootAccount - Optional root account to filter by (e.g., "Expenses")
|
* @param rootAccount - Optional root account to filter by (e.g., "Expenses")
|
||||||
* @param filterByUser - If true, only return accounts the user has permissions for
|
* @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(
|
async getAccountHierarchy(
|
||||||
walletKey: string,
|
walletKey: string,
|
||||||
rootAccount?: string,
|
rootAccount?: string,
|
||||||
filterByUser: boolean = false
|
filterByUser: boolean = false,
|
||||||
|
excludeVirtual: boolean = true
|
||||||
): Promise<AccountNode[]> {
|
): Promise<AccountNode[]> {
|
||||||
const accounts = await this.getAccounts(walletKey, filterByUser)
|
const accounts = await this.getAccounts(walletKey, filterByUser, excludeVirtual)
|
||||||
|
|
||||||
// Filter by root account if specified
|
// Filter by root account if specified
|
||||||
let filteredAccounts = accounts
|
let filteredAccounts = accounts
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue