Fix return type of AuthHeaders
This commit is contained in:
		| @@ -1,20 +1,5 @@ | |||||||
| export const store = createStore<State>({ | export const store = createStore<State>({ | ||||||
|     actions: { |     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}) { |         /*async fetchDashboard ({state, commit, rootState}) { | ||||||
|             const response = await fetch("/api/v1/dashboard", { |             const response = await fetch("/api/v1/dashboard", { | ||||||
|                 headers: { |                 headers: { | ||||||
| @@ -24,22 +9,6 @@ export const store = createStore<State>({ | |||||||
|             const data = await response.json(); |             const data = await response.json(); | ||||||
|             commit("setBudgets", data.Budgets); |             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()], |     plugins: [createLogger()], | ||||||
|     modules: { |     modules: { | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| import { defineStore } from "pinia"; | import { defineStore } from "pinia"; | ||||||
|  | import { useAPI } from "./api"; | ||||||
| import { Budget, useSessionStore } from "./session"; | import { Budget, useSessionStore } from "./session"; | ||||||
|  |  | ||||||
| interface State { | interface State { | ||||||
| @@ -7,7 +8,7 @@ interface State { | |||||||
|  |  | ||||||
| export const useBudgetsStore = defineStore('budget', { | export const useBudgetsStore = defineStore('budget', { | ||||||
|     state: (): State => ({ |     state: (): State => ({ | ||||||
|       CurrentBudgetID: null   |         CurrentBudgetID: null   | ||||||
|     }), |     }), | ||||||
|     actions: { |     actions: { | ||||||
|         setCurrentBudgetID(budgetid : string) { |         setCurrentBudgetID(budgetid : string) { | ||||||
| @@ -22,11 +23,37 @@ export const useBudgetsStore = defineStore('budget', { | |||||||
|             const sessionStore = useSessionStore(); |             const sessionStore = useSessionStore(); | ||||||
|             return sessionStore.Budgets.get(this.CurrentBudgetID); |             return sessionStore.Budgets.get(this.CurrentBudgetID); | ||||||
|         }, |         }, | ||||||
|         CurrentBudgetName(state) : string { |         CurrentBudgetName() : string { | ||||||
|             return this.CurrentBudget?.Name ?? ""; |             return this.CurrentBudget?.Name ?? ""; | ||||||
|         }, |         }, | ||||||
|         CurrentBudgetID() : string | undefined { |         CurrentBudgetID() : string | undefined { | ||||||
|             return this.CurrentBudgetID; |             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> { |         Budgets(): IterableIterator<Budget> { | ||||||
|             return this.Budgets.values(); |             return this.Budgets.values(); | ||||||
|         }, |         }, | ||||||
|         AuthHeaders(): Object { |         AuthHeaders(): HeadersInit { | ||||||
|             return { |             return { | ||||||
|                 'Authorization': 'Bearer ' + this.Token |                 'Authorization': 'Bearer ' + this.Token | ||||||
|             } |             } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user