Handle EditAccount in Store
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing

This commit is contained in:
Jan Bader 2022-02-24 22:12:35 +00:00
parent 466df523ab
commit ab07d3472d
2 changed files with 9 additions and 0 deletions

View File

@ -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<number, Map<string, Category>>();

View File

@ -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);
}