Fix return type of AuthHeaders
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { useAPI } from "./api";
|
||||
import { Budget, useSessionStore } from "./session";
|
||||
|
||||
interface State {
|
||||
@ -7,7 +8,7 @@ interface State {
|
||||
|
||||
export const useBudgetsStore = defineStore('budget', {
|
||||
state: (): State => ({
|
||||
CurrentBudgetID: null
|
||||
CurrentBudgetID: null
|
||||
}),
|
||||
actions: {
|
||||
setCurrentBudgetID(budgetid : string) {
|
||||
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user