From adc6e0a2cf197c3ef52149ebfa75d35821445b74 Mon Sep 17 00:00:00 2001 From: Jan Bader Date: Mon, 29 Jan 2024 22:51:31 +0100 Subject: [PATCH] Split FORM and regular POST --- web/src/api.ts | 14 +++++++++++++- web/src/stores/budget.ts | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/web/src/api.ts b/web/src/api.ts index 83fc203..9d02afa 100644 --- a/web/src/api.ts +++ b/web/src/api.ts @@ -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(); return fetch(BASE_URL + path, { method: "POST", @@ -19,6 +19,18 @@ export function POST(path: string, body: FormData | string | null) { 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) { const sessionStore = useSessionStore(); return fetch(BASE_URL + path, { diff --git a/web/src/stores/budget.ts b/web/src/stores/budget.ts index 1c42919..b92ea63 100644 --- a/web/src/stores/budget.ts +++ b/web/src/stores/budget.ts @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import { GET, POST } from "../api"; +import { GET, POST, FORM } from "../api"; import { useAccountStore } from "./budget-account"; import { useCategoryStore } from "./category"; import { Budget, useSessionStore } from "./session"; @@ -25,9 +25,9 @@ export const useBudgetsStore = defineStore("budget", { }, actions: { ImportYNAB(formData: FormData) { - return POST( + return FORM( "/budget/" + this.CurrentBudgetID + "/import/ynab", - formData + formData, ); }, async NewBudget(budgetName: string): Promise {