Move new ui to ui directory
This commit is contained in:
parent
bb72c351ac
commit
f85758ef33
56 changed files with 0 additions and 0 deletions
34
ui/src/lib/response.js
Normal file
34
ui/src/lib/response.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
export class Response {
|
||||
constructor(res) {
|
||||
if (res) {
|
||||
this.update(res);
|
||||
}
|
||||
}
|
||||
|
||||
update({ id, id_question, id_user, value, time_submit, score, score_explaination, id_corrector, time_scored }) {
|
||||
this.id = id;
|
||||
this.id_question = id_question;
|
||||
this.id_user = id_user;
|
||||
this.value = value;
|
||||
this.time_submit = time_submit;
|
||||
this.score = score;
|
||||
this.score_explaination = score_explaination;
|
||||
this.id_corrector = id_corrector;
|
||||
this.time_scored = time_scored;
|
||||
}
|
||||
|
||||
async save() {
|
||||
const res = await fetch(`api/questions/${this.id_question}/responses/${this.id}`, {
|
||||
method: 'PUT',
|
||||
headers: {'Accept': 'application/json'},
|
||||
body: JSON.stringify(this),
|
||||
});
|
||||
if (res.status == 200) {
|
||||
const data = await res.json();
|
||||
this.update(data);
|
||||
return data;
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue