Can mark need help as treated
This commit is contained in:
parent
bb7c4f32e4
commit
9c0e35b1e2
3 changed files with 68 additions and 6 deletions
|
|
@ -51,10 +51,51 @@ export async function getUserScore(uid, survey) {
|
|||
}
|
||||
}
|
||||
|
||||
export class UserNeedingHelp {
|
||||
constructor(res) {
|
||||
if (res) {
|
||||
this.update(res);
|
||||
}
|
||||
}
|
||||
|
||||
update({ id, id_user, date, comment, treated }) {
|
||||
this.id = id;
|
||||
this.id_user = id_user;
|
||||
this.date = new Date(date);
|
||||
this.comment = comment;
|
||||
if (treated) {
|
||||
this.treated = new Date(treated);
|
||||
} else {
|
||||
this.treated = null;
|
||||
}
|
||||
}
|
||||
|
||||
mark_treated() {
|
||||
this.treated = new Date();
|
||||
}
|
||||
|
||||
async save() {
|
||||
const res = await fetch(this.id?`api/help/${this.id}`:'api/help', {
|
||||
method: this.id?'PUT':'POST',
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserNeedingHelp() {
|
||||
const res = await fetch(`api/help`, {headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
return await res.json();
|
||||
return (await res.json()).map((nh) => {
|
||||
return new UserNeedingHelp(nh)
|
||||
});
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue