Add button to easily upgrade user promo
This commit is contained in:
parent
cb147e2b96
commit
0f8d77b05f
2 changed files with 45 additions and 1 deletions
|
|
@ -16,10 +16,45 @@ export async function getUsers() {
|
|||
}
|
||||
}
|
||||
|
||||
export class User {
|
||||
constructor(res) {
|
||||
if (res) {
|
||||
this.update(res);
|
||||
}
|
||||
}
|
||||
|
||||
update({ id, login, email, firstname, lastname, time, promo, groups, is_admin }) {
|
||||
this.id = id;
|
||||
this.login = login;
|
||||
this.email = email;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.time = time;
|
||||
this.promo = promo;
|
||||
this.groups = groups;
|
||||
this.is_admin = is_admin;
|
||||
}
|
||||
|
||||
async save() {
|
||||
const res = await fetch(this.id?`api/users/${this.id}`:'api/users', {
|
||||
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 getUser(uid) {
|
||||
const res = await fetch(`api/users/${uid}`, {headers: {'Accept': 'application/json'}})
|
||||
if (res.status == 200) {
|
||||
return await res.json();
|
||||
return new User(await res.json());
|
||||
} else {
|
||||
throw new Error((await res.json()).errmsg);
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue