diff --git a/web/src/App.vue b/web/src/App.vue index fa12ea3..d6496af 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -1,7 +1,6 @@ @@ -18,7 +23,7 @@ export default defineComponent({ {{ transaction.CategoryGroup ? transaction.CategoryGroup + " : " + transaction.Category : "" }} - + {{ transaction.Memo }} diff --git a/web/src/pages/Account.vue b/web/src/pages/Account.vue index 19a5503..3dcf60f 100644 --- a/web/src/pages/Account.vue +++ b/web/src/pages/Account.vue @@ -4,6 +4,7 @@ import { defineComponent } from "vue" import Autocomplete, { Suggestion } from '../components/Autocomplete.vue' import Currency from "../components/Currency.vue"; import TransactionRow from "../components/TransactionRow.vue"; +import { useAPI } from "../stores/api"; import { useAccountStore } from "../stores/budget-account"; import { useSessionStore } from "../stores/session"; @@ -25,9 +26,8 @@ export default defineComponent({ methods: { saveTransaction(e : MouseEvent) { e.preventDefault(); - fetch("/api/v1/transaction/new", { - method: "POST", - body: JSON.stringify({ + const api = useAPI(); + api.POST("/transaction/new", JSON.stringify({ budget_id: this.budgetid, account_id: this.accountid, date: this.$data.TransactionDate, @@ -36,9 +36,7 @@ export default defineComponent({ memo: this.$data.Memo, amount: this.$data.Amount, state: "Uncleared" - }), - headers: useSessionStore().AuthHeaders, - }) + })) .then(x => x.json()); }, } diff --git a/web/src/pages/Budgeting.vue b/web/src/pages/Budgeting.vue index 0340e7a..55dd8d4 100644 --- a/web/src/pages/Budgeting.vue +++ b/web/src/pages/Budgeting.vue @@ -12,7 +12,7 @@ interface Date { export default defineComponent({ mounted() { - document.title = "Budgeteer - Budget for " + this.month + " " + this.year; + document.title = "Budgeteer - Budget for " + this.selected.Month + "/" + this.selected.Year; return useAccountStore().FetchMonthBudget(this.budgetid, this.year, this.month); }, watch: { @@ -27,7 +27,9 @@ export default defineComponent({ computed: { ...mapState(useBudgetsStore, ["CurrentBudgetID"]), Categories() : IterableIterator | undefined { - return useAccountStore().Categories(this.year, this.month); + const accountStore = useAccountStore(); + console.log(accountStore.CategoriesForMonth(this.year, this.month)); + return accountStore.CategoriesForMonth(this.year, this.month); }, previous(): Date { return { diff --git a/web/src/pages/Settings.vue b/web/src/pages/Settings.vue index c68dd8e..be1c7ea 100644 --- a/web/src/pages/Settings.vue +++ b/web/src/pages/Settings.vue @@ -36,7 +36,7 @@ export default defineComponent({ return; const api = useAPI(); - api.DELETE("/api/v1/budget/" + currentBudgetID); + api.DELETE("/budget/" + currentBudgetID); const budgetStore = useSessionStore(); budgetStore.Budgets.delete(currentBudgetID); @@ -45,7 +45,7 @@ export default defineComponent({ clearBudget() { const currentBudgetID = useBudgetsStore().CurrentBudgetID; const api = useAPI(); - api.POST("/api/v1/budget/" + currentBudgetID + "/settings/clear", null) + api.POST("/budget/" + currentBudgetID + "/settings/clear", null) }, cleanNegative() { // Fix all historic negative category-balances diff --git a/web/src/stores/budget-account.ts b/web/src/stores/budget-account.ts index 641c762..5f53e46 100644 --- a/web/src/stores/budget-account.ts +++ b/web/src/stores/budget-account.ts @@ -1,5 +1,4 @@ import { defineStore } from "pinia" -import { FETCH_ACCOUNT } from "../store/action-types"; import { useAPI } from "./api"; import { useSessionStore } from "./session"; @@ -42,7 +41,8 @@ export const useAccountStore = defineStore("budget/account", { AccountsList(state) { return state.Accounts.values(); }, - Categories: (state) => (year : number, month : number) => { + CategoriesForMonth: (state) => (year : number, month : number) => { + console.log("MTH", state.Months) const yearMap = state.Months.get(year); return yearMap?.get(month)?.values(); }, @@ -64,7 +64,7 @@ export const useAccountStore = defineStore("budget/account", { OffBudgetAccountsBalance(state) : Number { return this.OffBudgetAccounts.reduce((prev, curr) => prev + Number(curr.Balance), 0); }, - Transactions(state) { + TransactionsList(state) { return (state.Transactions || []); } }, @@ -82,11 +82,11 @@ export const useAccountStore = defineStore("budget/account", { }, async FetchAccount(accountid : string) { const api = useAPI(); - const result = await api.GET("/api/v1/account/" + accountid + "/transactions"); + const result = await api.GET("/account/" + accountid + "/transactions"); const response = await result.json(); this.Transactions = response.Transactions; }, - async FetchMonthBudget(budgetid : string, month : number, year : number) { + async FetchMonthBudget(budgetid : string, year : number, month : number) { const api = useAPI(); const result = await api.GET("/budget/" + budgetid + "/" + year + "/" + month); const response = await result.json(); diff --git a/web/src/stores/session.ts b/web/src/stores/session.ts index 1415d9e..2052534 100644 --- a/web/src/stores/session.ts +++ b/web/src/stores/session.ts @@ -1,4 +1,5 @@ import { defineStore } from 'pinia' +import { useAPI } from './api'; interface State { Token: string | null @@ -33,17 +34,18 @@ export const useSessionStore = defineStore('session', { this.Token = x.Token; this.Budgets = x.Budgets; }, - login(login: any) { - return fetch("/api/v1/user/login", { method: "POST", body: JSON.stringify(login) }) - .then(x => x.json()) - .then(x => this.loginSuccess(x)); + async login(login: any) { + const api = useAPI(); + const response = await api.POST("/user/login", JSON.stringify(login)); + const result = await response.json(); + return this.loginSuccess(result); }, - register(login : any) { - return fetch("/api/v1/user/register", { method: "POST", body: JSON.stringify(login) }) - .then(x => x.json()) - .then(x => this.loginSuccess(x)) + async register(login : any) { + const api = useAPI(); + const response = await api.POST("/user/register", JSON.stringify(login)); + const result = await response.json(); + return this.loginSuccess(result); }, - // easily reset state using `$reset` logout() { this.$reset() }