New route to delete grades
This commit is contained in:
parent
6f9b83ef24
commit
706e786190
5 changed files with 107 additions and 5 deletions
31
ui/src/lib/grades.js
Normal file
31
ui/src/lib/grades.js
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue