From f417e575ea722f93964db841564dbed64406c5f8 Mon Sep 17 00:00:00 2001 From: haraldnilsen Date: Wed, 10 Jan 2024 20:59:00 +0100 Subject: [PATCH] :alien: added async to api calls Co-authored-by: Sindre Kjelsrud --- frontend/src/api/getUserQuestions.ts | 4 +++- frontend/src/api/postBugData.ts | 2 +- frontend/src/api/postEvaluationData.ts | 2 +- frontend/src/api/postFormData.ts | 5 ++++- frontend/src/api/postUserformData.ts | 2 +- frontend/src/components/form/footer/Footer.svelte | 5 +++-- frontend/src/routes/evaluation/+page.svelte | 4 ++-- frontend/src/routes/reportbug/+page.svelte | 4 ++-- 8 files changed, 17 insertions(+), 11 deletions(-) diff --git a/frontend/src/api/getUserQuestions.ts b/frontend/src/api/getUserQuestions.ts index 91b7bfe..ecfb3a5 100644 --- a/frontend/src/api/getUserQuestions.ts +++ b/frontend/src/api/getUserQuestions.ts @@ -19,7 +19,9 @@ interface QAData { questions: QuestionAnswerPair[]; } -export const getUserQuestions = (respondentID: number): Promise => { +export const getUserQuestions = async ( + respondentID: number +): Promise => { let url = `http://localhost:8080/userquestions?respondentID=${respondentID}`; const response = fetch(url, { diff --git a/frontend/src/api/postBugData.ts b/frontend/src/api/postBugData.ts index 1d9943f..5d7ceeb 100644 --- a/frontend/src/api/postBugData.ts +++ b/frontend/src/api/postBugData.ts @@ -1,4 +1,4 @@ -export const postBugData = (bugText: string) => { +export const postBugData = async (bugText: string) => { let url = "http://localhost:8080/submitbug"; const response = fetch(url, { diff --git a/frontend/src/api/postEvaluationData.ts b/frontend/src/api/postEvaluationData.ts index 62ebf74..bd7c84d 100644 --- a/frontend/src/api/postEvaluationData.ts +++ b/frontend/src/api/postEvaluationData.ts @@ -1,4 +1,4 @@ -export const postEvaluationData = (evaluationText: string) => { +export const postEvaluationData = async (evaluationText: string) => { let url = "http://localhost:8080/submiteval"; const response = fetch(url, { diff --git a/frontend/src/api/postFormData.ts b/frontend/src/api/postFormData.ts index 6ee7b20..7006a1c 100644 --- a/frontend/src/api/postFormData.ts +++ b/frontend/src/api/postFormData.ts @@ -1,4 +1,7 @@ -export const postFormData = (respondentID: number, allFormAnswers: string) => { +export const postFormData = async ( + respondentID: number, + allFormAnswers: string +) => { let url = "http://localhost:8080/submitanswers"; const response = fetch(url, { diff --git a/frontend/src/api/postUserformData.ts b/frontend/src/api/postUserformData.ts index 0ee076a..772acf1 100644 --- a/frontend/src/api/postUserformData.ts +++ b/frontend/src/api/postUserformData.ts @@ -2,7 +2,7 @@ interface postUserformDataReponse { respondentID: number; } -export const postUserformData = ( +export const postUserformData = async ( age: string, education: string, healthcare_personnel: string, diff --git a/frontend/src/components/form/footer/Footer.svelte b/frontend/src/components/form/footer/Footer.svelte index cdd7c34..afc9da3 100644 --- a/frontend/src/components/form/footer/Footer.svelte +++ b/frontend/src/components/form/footer/Footer.svelte @@ -15,12 +15,13 @@ goto(`${questionNum - 1}`) } - const handleFormSubmit = () => { + const handleFormSubmit = async () => { let allFormAnswers:string | null = localStorage.getItem("allFormAnswers") let respondentID:string | null = localStorage.getItem("RespondentId") if (allFormAnswers && respondentID) { - postFormData(Number(respondentID), allFormAnswers) + await postFormData(Number(respondentID), allFormAnswers) + goto("/evaluation") } } diff --git a/frontend/src/routes/evaluation/+page.svelte b/frontend/src/routes/evaluation/+page.svelte index 5361b3f..5df36d5 100644 --- a/frontend/src/routes/evaluation/+page.svelte +++ b/frontend/src/routes/evaluation/+page.svelte @@ -4,9 +4,9 @@ let evaluationText:string = "" - const handleEvaluationSubmit = () => { + const handleEvaluationSubmit = async () => { if (evaluationText) { - postEvaluationData(evaluationText) + await postEvaluationData(evaluationText) goto("/") } else { console.log("error"); diff --git a/frontend/src/routes/reportbug/+page.svelte b/frontend/src/routes/reportbug/+page.svelte index 20ebad1..f88cf7f 100644 --- a/frontend/src/routes/reportbug/+page.svelte +++ b/frontend/src/routes/reportbug/+page.svelte @@ -4,9 +4,9 @@ let bugText:string = "" - const handleBugSubmit = () => { + const handleBugSubmit = async () => { if (bugText) { - postBugData(bugText) + await postBugData(bugText) goto("javascript:history.back()") } else { console.log("error");