This commit is contained in:
parent
240a8576ca
commit
4d77cde945
7 changed files with 95 additions and 43 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import { getQuestions } from './questions';
|
||||
|
||||
|
||||
class Survey {
|
||||
export class Survey {
|
||||
constructor(res) {
|
||||
if (res) {
|
||||
this.update(res);
|
||||
|
|
|
|||
Reference in a new issue