New route to delete grades

This commit is contained in:
nemunaire 2023-03-05 13:17:25 +01:00
commit 706e786190
5 changed files with 107 additions and 5 deletions

31
ui/src/lib/grades.js Normal file
View file

@ -0,0 +1,31 @@
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);
}
}
}
}

View file

@ -1,3 +1,5 @@
import { Grade } from '$lib/grades';
export class Work {
constructor(res) {
this.kind = "w";
@ -110,7 +112,7 @@ export class Work {
headers: {'Accept': 'application/json'},
});
if (res.status == 200) {
return await res.json();
return (await res.json()).map((g) => new Grade(g));
} else {
throw new Error((await res.json()).errmsg);
}