Fix return type of AuthHeaders
This commit is contained in:
parent
0c094d6f6b
commit
8b0e368d58
@ -1,20 +1,5 @@
|
||||
export const store = createStore<State>({
|
||||
actions: {
|
||||
[IMPORT_YNAB]({ getters, dispatch }, formData) {
|
||||
return dispatch("POST", { path: "/budget/" + getters.CurrentBudget.ID + "/import/ynab", body: formData });
|
||||
},
|
||||
[GET]({ getters }, { path }) {
|
||||
return fetch("/api/v1" + path, {
|
||||
headers: getters.AuthHeaders,
|
||||
})
|
||||
},
|
||||
[POST]({ getters }, { path, body }) {
|
||||
return fetch("/api/v1" + path, {
|
||||
method: "POST",
|
||||
headers: getters.AuthHeaders,
|
||||
body: body,
|
||||
})
|
||||
},
|
||||
/*async fetchDashboard ({state, commit, rootState}) {
|
||||
const response = await fetch("/api/v1/dashboard", {
|
||||
headers: {
|
||||
@ -24,22 +9,6 @@ export const store = createStore<State>({
|
||||
const data = await response.json();
|
||||
commit("setBudgets", data.Budgets);
|
||||
},*/
|
||||
async [NEW_BUDGET]({ state, commit, dispatch, rootState }, budgetName) {
|
||||
const result = await dispatch("POST", {
|
||||
path: "/budget/new",
|
||||
body: JSON.stringify({ name: budgetName })
|
||||
});
|
||||
const response = await result.json();
|
||||
commit("addBudget", response)
|
||||
},
|
||||
async [SET_CURRENT_BUDGET]({ state, commit, dispatch, rootState }, budgetid) {
|
||||
commit("setCurrentBudgetID", budgetid);
|
||||
|
||||
if (budgetid == null)
|
||||
return
|
||||
|
||||
await dispatch(FETCH_BUDGET, budgetid)
|
||||
},
|
||||
},
|
||||
plugins: [createLogger()],
|
||||
modules: {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useAPI } from "./api";
|
||||
import { Budget, useSessionStore } from "./session";
|
||||
|
||||
interface State {
|
||||
@ -22,11 +23,37 @@ export const useBudgetsStore = defineStore('budget', {
|
||||
const sessionStore = useSessionStore();
|
||||
return sessionStore.Budgets.get(this.CurrentBudgetID);
|
||||
},
|
||||
CurrentBudgetName(state) : string {
|
||||
CurrentBudgetName() : string {
|
||||
return this.CurrentBudget?.Name ?? "";
|
||||
},
|
||||
CurrentBudgetID() : string | undefined {
|
||||
return this.CurrentBudgetID;
|
||||
},
|
||||
ImportYNAB(formData) {
|
||||
const api = useAPI();
|
||||
return api.POST(
|
||||
"/budget/" + this.CurrentBudgetID + "/import/ynab",
|
||||
formData
|
||||
);
|
||||
},
|
||||
async NewBudget(budgetName) {
|
||||
const api = useAPI();
|
||||
const result = await api.POST(
|
||||
"/budget/new",
|
||||
JSON.stringify({ name: budgetName })
|
||||
);
|
||||
const response = await result.json();
|
||||
|
||||
const sessionStore = useSessionStore();
|
||||
sessionStore.Budgets.set(response.ID, response);
|
||||
},
|
||||
async SetCurrentBudget(budgetid : string) {
|
||||
this.CurrentBudgetID = budgetid;
|
||||
|
||||
if (budgetid == null)
|
||||
return
|
||||
|
||||
await dispatch(FETCH_BUDGET, budgetid)
|
||||
},
|
||||
}
|
||||
})
|
@ -23,7 +23,7 @@ export const useSessionStore = defineStore('session', {
|
||||
Budgets(): IterableIterator<Budget> {
|
||||
return this.Budgets.values();
|
||||
},
|
||||
AuthHeaders(): Object {
|
||||
AuthHeaders(): HeadersInit {
|
||||
return {
|
||||
'Authorization': 'Bearer ' + this.Token
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user