Split FORM and regular POST
Some checks reported errors
continuous-integration/drone/pr Build encountered an error
continuous-integration/drone/push Build is passing

This commit is contained in:
Jan Bader 2024-01-29 22:51:31 +01:00
parent 4d04529ae2
commit adc6e0a2cf
2 changed files with 16 additions and 4 deletions

View File

@ -9,7 +9,7 @@ export function GET(path: string) {
}); });
} }
export function POST(path: string, body: FormData | string | null) { export function FORM(path: string, body: FormData) {
const sessionStore = useSessionStore(); const sessionStore = useSessionStore();
return fetch(BASE_URL + path, { return fetch(BASE_URL + path, {
method: "POST", method: "POST",
@ -19,6 +19,18 @@ export function POST(path: string, body: FormData | string | null) {
body: body, body: body,
}); });
} }
export function POST(path: string, body: string | null) {
const sessionStore = useSessionStore();
return fetch(BASE_URL + path, {
method: "POST",
headers: {
...sessionStore.AuthHeaders,
"Content-Type": "application/json"
},
body: body,
});
}
export function DELETE(path: string) { export function DELETE(path: string) {
const sessionStore = useSessionStore(); const sessionStore = useSessionStore();
return fetch(BASE_URL + path, { return fetch(BASE_URL + path, {

View File

@ -1,5 +1,5 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { GET, POST } from "../api"; import { GET, POST, FORM } from "../api";
import { useAccountStore } from "./budget-account"; import { useAccountStore } from "./budget-account";
import { useCategoryStore } from "./category"; import { useCategoryStore } from "./category";
import { Budget, useSessionStore } from "./session"; import { Budget, useSessionStore } from "./session";
@ -25,9 +25,9 @@ export const useBudgetsStore = defineStore("budget", {
}, },
actions: { actions: {
ImportYNAB(formData: FormData) { ImportYNAB(formData: FormData) {
return POST( return FORM(
"/budget/" + this.CurrentBudgetID + "/import/ynab", "/budget/" + this.CurrentBudgetID + "/import/ynab",
formData formData,
); );
}, },
async NewBudget(budgetName: string): Promise<void> { async NewBudget(budgetName: string): Promise<void> {