32 lines
676 B
JavaScript
32 lines
676 B
JavaScript
export class Grade {
|
|
constructor(res) {
|
|
if (res) {
|
|
this.update(res);
|
|
}
|
|
}
|
|
|
|
update({ id, login, id_user, id_work, date, score, comment }) {
|
|
this.id = id;
|
|
this.login = login;
|
|
this.id_user = id_user;
|
|
this.id_work = id_work;
|
|
this.date = date;
|
|
this.score = score;
|
|
this.comment = comment;
|
|
}
|
|
|
|
async delete() {
|
|
if (this.id) {
|
|
const res = await fetch(`api/works/${this.id_work}/grades/${this.id}`, {
|
|
method: 'DELETE',
|
|
headers: {'Accept': 'application/json'},
|
|
});
|
|
if (res.status == 200) {
|
|
return true;
|
|
} else {
|
|
throw new Error((await res.json()).errmsg);
|
|
}
|
|
}
|
|
}
|
|
}
|