2021-02-09 16:04:55 +00:00
|
|
|
import { DefaultClient, AKResponse } from "./Client";
|
2020-11-26 21:37:41 +00:00
|
|
|
|
2020-12-06 11:38:19 +00:00
|
|
|
let _globalMePromise: Promise<User>;
|
2020-12-02 12:56:26 +00:00
|
|
|
|
2020-11-26 21:37:41 +00:00
|
|
|
export class User {
|
2020-12-01 12:59:59 +00:00
|
|
|
pk: number;
|
|
|
|
username: string;
|
|
|
|
name: string;
|
|
|
|
is_superuser: boolean;
|
|
|
|
email: boolean;
|
|
|
|
avatar: string;
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
throw Error();
|
|
|
|
}
|
2020-11-22 18:37:09 +00:00
|
|
|
|
2020-11-26 21:37:41 +00:00
|
|
|
static me(): Promise<User> {
|
2020-12-06 11:38:19 +00:00
|
|
|
if (!_globalMePromise) {
|
|
|
|
_globalMePromise = DefaultClient.fetch<User>(["core", "users", "me"]);
|
2020-12-02 12:56:26 +00:00
|
|
|
}
|
2020-12-06 11:38:19 +00:00
|
|
|
return _globalMePromise;
|
2020-11-26 21:37:41 +00:00
|
|
|
}
|
2020-12-01 11:41:37 +00:00
|
|
|
|
|
|
|
static count(): Promise<number> {
|
2021-02-09 16:04:55 +00:00
|
|
|
return DefaultClient.fetch<AKResponse<User>>(["core", "users"], {
|
2020-12-01 11:41:37 +00:00
|
|
|
"page_size": 1
|
|
|
|
}).then(r => {
|
|
|
|
return r.pagination.count;
|
|
|
|
});
|
|
|
|
}
|
2020-11-22 12:43:41 +00:00
|
|
|
}
|