Add button to easily upgrade user promo
This commit is contained in:
parent
cb147e2b96
commit
0f8d77b05f
@ -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);
|
||||
}
|
||||
|
@ -41,6 +41,15 @@
|
||||
</h2>
|
||||
{#if student.promo}
|
||||
<span class="badge bg-success ms-1">{student.promo}</span>
|
||||
{#if $user && $user.is_admin && $user.current_promo && student.promo != $user.current_promo}
|
||||
<button
|
||||
class="btn btn-sm btn-warning mx-1"
|
||||
title="Passer sur la promo en cours"
|
||||
on:click={() => { student.promo = $user.current_promo; student.save(); }}
|
||||
>
|
||||
<i class="bi bi-arrow-up"></i>
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
|
Reference in New Issue
Block a user