Fixes survey creation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
nemunaire 2022-03-01 20:21:49 +01:00
commit 4d77cde945
7 changed files with 95 additions and 43 deletions

View file

@ -68,7 +68,12 @@ export class Question {
headers: {'Accept': 'application/json'},
});
if (res.status == 200) {
return (await res.json()).map((p) => new QuestionProposal(p))
const data = await res.json();
if (data === null) {
return [];
} else {
return (data).map((p) => new QuestionProposal(p))
}
} else {
throw new Error((await res.json()).errmsg);
}
@ -140,7 +145,12 @@ export async function getQuestion(qid) {
export async function getQuestions(sid) {
const res = await fetch(`api/surveys/${sid}/questions`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
return (await res.json()).map((e) => new Question(e))
const data = await res.json();
if (data === null) {
return [];
} else {
return (data).map((q) => new Question(q))
}
} else {
throw new Error((await res.json()).errmsg);
}

View file

@ -1,7 +1,6 @@
import { getQuestions } from './questions';
class Survey {
export class Survey {
constructor(res) {
if (res) {
this.update(res);