Handle EditAccount in Store
This commit is contained in:
parent
466df523ab
commit
ab07d3472d
@ -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>>();
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user