From ab07d3472d0000504889a1e96a0ae3b6df2d0ef6 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Thu, 24 Feb 2022 22:12:35 +0000 Subject: [PATCH] Handle EditAccount in Store --- web/src/stores/budget-account.ts | 6 ++++++ web/src/stores/budget.ts | 3 +++ 2 files changed, 9 insertions(+) diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index be57f7d..c612c0d 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -1,5 +1,6 @@ import { defineStore } from "pinia" import { GET, POST } from "../api"; +import { useBudgetsStore } from "./budget"; import { useSessionStore } from "./session"; interface State { @@ -124,6 +125,11 @@ export const useAccountStore = defineStore("budget/account", { return; this.addCategoriesForMonth(year, month, response.Categories); }, + async EditAccount(accountid : string, name : string, onBudget : boolean) { + const result = await POST("/account/" + accountid, JSON.stringify({name: name, onBudget: onBudget})); + const response = await result.json(); + useBudgetsStore().MergeBudgetingData(response); + }, addCategoriesForMonth(year: number, month: number, categories: Category[]): void { this.$patch((state) => { const yearMap = state.Months.get(year) || new Map>(); diff --git a/web/src/stores/budget.ts b/web/src/stores/budget.ts index 2d3d1be..919996f 100644 --- a/web/src/stores/budget.ts +++ b/web/src/stores/budget.ts @@ -51,6 +51,9 @@ export const useBudgetsStore = defineStore('budget', { async FetchBudget(budgetid: string) { const result = await GET("/budget/" + budgetid); const response = await result.json(); + this.MergeBudgetingData(response); + }, + MergeBudgetingData(response : any) { for (const account of response.Accounts || []) { useAccountStore().Accounts.set(account.ID, account); }