Implement editing of Accounts #20
@ -1,5 +1,6 @@
|
|||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
import { GET, POST } from "../api";
|
import { GET, POST } from "../api";
|
||||||
|
import { useBudgetsStore } from "./budget";
|
||||||
import { useSessionStore } from "./session";
|
import { useSessionStore } from "./session";
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@ -124,6 +125,11 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
return;
|
return;
|
||||||
this.addCategoriesForMonth(year, month, response.Categories);
|
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 {
|
addCategoriesForMonth(year: number, month: number, categories: Category[]): void {
|
||||||
this.$patch((state) => {
|
this.$patch((state) => {
|
||||||
const yearMap = state.Months.get(year) || new Map<number, Map<string, Category>>();
|
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) {
|
async FetchBudget(budgetid: string) {
|
||||||
const result = await GET("/budget/" + budgetid);
|
const result = await GET("/budget/" + budgetid);
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
this.MergeBudgetingData(response);
|
||||||
|
},
|
||||||
|
MergeBudgetingData(response : any) {
|
||||||
for (const account of response.Accounts || []) {
|
for (const account of response.Accounts || []) {
|
||||||
useAccountStore().Accounts.set(account.ID, account);
|
useAccountStore().Accounts.set(account.ID, account);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user