Add Transaction to list after saving
This commit is contained in:
parent
73e3b49b40
commit
16b7049438
@ -68,8 +68,11 @@ func (h *Handler) newTransaction(c *gin.Context) {
|
|||||||
CategoryID: payload.Category.ID,
|
CategoryID: payload.Category.ID,
|
||||||
Status: postgres.TransactionStatus(payload.State),
|
Status: postgres.TransactionStatus(payload.State),
|
||||||
}
|
}
|
||||||
_, err = h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
transaction, err := h.Service.CreateTransaction(c.Request.Context(), newTransaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
c.AbortWithError(http.StatusInternalServerError, fmt.Errorf("create transaction: %w", err))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, transaction)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
import { POST } from "../api";
|
|
||||||
import Autocomplete, { Suggestion } from '../components/Autocomplete.vue'
|
import Autocomplete, { Suggestion } from '../components/Autocomplete.vue'
|
||||||
|
import { useAccountStore } from '../stores/budget-account'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
budgetid: string
|
budgetid: string
|
||||||
@ -12,11 +12,9 @@ const TransactionDate = ref(new Date().toISOString().substring(0, 10));
|
|||||||
const Payee = ref<Suggestion | undefined>(undefined);
|
const Payee = ref<Suggestion | undefined>(undefined);
|
||||||
const Category = ref<Suggestion | undefined>(undefined);
|
const Category = ref<Suggestion | undefined>(undefined);
|
||||||
const Memo = ref("");
|
const Memo = ref("");
|
||||||
const Amount = ref("");
|
const Amount = ref("0");
|
||||||
|
|
||||||
function saveTransaction(e: MouseEvent) {
|
const payload = computed(() => JSON.stringify({
|
||||||
e.preventDefault();
|
|
||||||
POST("/transaction/new", JSON.stringify({
|
|
||||||
budget_id: props.budgetid,
|
budget_id: props.budgetid,
|
||||||
account_id: props.accountid,
|
account_id: props.accountid,
|
||||||
date: TransactionDate.value,
|
date: TransactionDate.value,
|
||||||
@ -25,8 +23,12 @@ function saveTransaction(e: MouseEvent) {
|
|||||||
memo: Memo.value,
|
memo: Memo.value,
|
||||||
amount: Amount.value,
|
amount: Amount.value,
|
||||||
state: "Uncleared"
|
state: "Uncleared"
|
||||||
}))
|
}));
|
||||||
.then(x => x.json());
|
|
||||||
|
const accountStore = useAccountStore();
|
||||||
|
function saveTransaction(e: MouseEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
accountStore.saveTransaction(payload.value);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed, ref } from "vue"
|
import { computed, ref } from "vue"
|
||||||
import Autocomplete, { Suggestion } from '../components/Autocomplete.vue'
|
|
||||||
import Currency from "../components/Currency.vue";
|
import Currency from "../components/Currency.vue";
|
||||||
import TransactionRow from "../components/TransactionRow.vue";
|
import TransactionRow from "../components/TransactionRow.vue";
|
||||||
import TransactionInputRow from "../components/TransactionInputRow.vue";
|
import TransactionInputRow from "../components/TransactionInputRow.vue";
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from "pinia"
|
import { defineStore } from "pinia"
|
||||||
import { GET } from "../api";
|
import { GET, POST } from "../api";
|
||||||
import { useSessionStore } from "./session";
|
import { useSessionStore } from "./session";
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
@ -7,7 +7,7 @@ interface State {
|
|||||||
CurrentAccountID: string | null,
|
CurrentAccountID: string | null,
|
||||||
Categories: Map<string, Category>,
|
Categories: Map<string, Category>,
|
||||||
Months: Map<number, Map<number, Map<string, Category>>>,
|
Months: Map<number, Map<number, Map<string, Category>>>,
|
||||||
Transactions: [],
|
Transactions: any[],
|
||||||
Assignments: []
|
Assignments: []
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ export interface Transaction {
|
|||||||
Date: string,
|
Date: string,
|
||||||
TransferAccount: string,
|
TransferAccount: string,
|
||||||
CategoryGroup: string,
|
CategoryGroup: string,
|
||||||
Category:string,
|
Category: string,
|
||||||
Memo: string,
|
Memo: string,
|
||||||
Status: string,
|
Status: string,
|
||||||
GroupID: string,
|
GroupID: string,
|
||||||
@ -69,13 +69,13 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
OnBudgetAccounts(state) {
|
OnBudgetAccounts(state) {
|
||||||
return [...state.Accounts.values()].filter(x => x.OnBudget);
|
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);
|
return this.OnBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0);
|
||||||
},
|
},
|
||||||
OffBudgetAccounts(state) {
|
OffBudgetAccounts(state) {
|
||||||
return [...state.Accounts.values()].filter(x => !x.OnBudget);
|
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);
|
return this.OffBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0);
|
||||||
},
|
},
|
||||||
TransactionsList(state) {
|
TransactionsList(state) {
|
||||||
@ -119,6 +119,11 @@ export const useAccountStore = defineStore("budget/account", {
|
|||||||
logout() {
|
logout() {
|
||||||
this.$reset()
|
this.$reset()
|
||||||
},
|
},
|
||||||
|
async saveTransaction(payload: string) {
|
||||||
|
const result = await POST("/transaction/new", payload);
|
||||||
|
const response = await result.json();
|
||||||
|
this.Transactions.unshift(response);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user