Add Transaction to list after saving
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { defineStore } from "pinia"
|
||||
import { GET } from "../api";
|
||||
import { GET, POST } from "../api";
|
||||
import { useSessionStore } from "./session";
|
||||
|
||||
interface State {
|
||||
@ -7,7 +7,7 @@ interface State {
|
||||
CurrentAccountID: string | null,
|
||||
Categories: Map<string, Category>,
|
||||
Months: Map<number, Map<number, Map<string, Category>>>,
|
||||
Transactions: [],
|
||||
Transactions: any[],
|
||||
Assignments: []
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ export interface Transaction {
|
||||
Date: string,
|
||||
TransferAccount: string,
|
||||
CategoryGroup: string,
|
||||
Category:string,
|
||||
Category: string,
|
||||
Memo: string,
|
||||
Status: string,
|
||||
GroupID: string,
|
||||
@ -69,13 +69,13 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
OnBudgetAccounts(state) {
|
||||
return [...state.Accounts.values()].filter(x => x.OnBudget);
|
||||
},
|
||||
OnBudgetAccountsBalance(state) : number {
|
||||
OnBudgetAccountsBalance(state): number {
|
||||
return this.OnBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0);
|
||||
},
|
||||
OffBudgetAccounts(state) {
|
||||
return [...state.Accounts.values()].filter(x => !x.OnBudget);
|
||||
},
|
||||
OffBudgetAccountsBalance(state) : number {
|
||||
OffBudgetAccountsBalance(state): number {
|
||||
return this.OffBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0);
|
||||
},
|
||||
TransactionsList(state) {
|
||||
@ -119,6 +119,11 @@ export const useAccountStore = defineStore("budget/account", {
|
||||
logout() {
|
||||
this.$reset()
|
||||
},
|
||||
async saveTransaction(payload: string) {
|
||||
const result = await POST("/transaction/new", payload);
|
||||
const response = await result.json();
|
||||
this.Transactions.unshift(response);
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
|
Reference in New Issue
Block a user