From b3b878854e7b1d07326672ba0180c7a09311605d Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Mon, 28 Feb 2022 09:28:53 +0000 Subject: [PATCH] Extract GetAccount --- web/src/stores/budget-account.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index 5697dbe..9ae89b1 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -90,11 +90,16 @@ export const useAccountStore = defineStore("budget/account", { return categories.filter(x => x.Group == group); } }, + GetAccount(state) { + return (accountid: string) => { + return this.Accounts.get(accountid); + } + }, CurrentAccount(state): Account | undefined { if (state.CurrentAccountID == null) return undefined; - return state.Accounts.get(state.CurrentAccountID); + return this.GetAccount(state.CurrentAccountID); }, ReconcilingBalance(state): number { let reconciledBalance = this.CurrentAccount!.ReconciledBalance; @@ -128,10 +133,7 @@ export const useAccountStore = defineStore("budget/account", { return this.CurrentAccountID = accountid; - const account = this.CurrentAccount; - if (account == undefined) - return - + const account = this.GetAccount(accountid)!; useSessionStore().setTitle(account.Name); await this.FetchAccount(account); },