2022-09-01 22:32:03 +00:00
|
|
|
import { Requests } from "~~/lib/requests";
|
|
|
|
import { BaseAPI, UrlBuilder } from "./base";
|
|
|
|
import { LocationsApi } from "./classes/locations";
|
2022-08-31 00:06:57 +00:00
|
|
|
|
|
|
|
export type Result<T> = {
|
2022-08-31 02:11:36 +00:00
|
|
|
item: T;
|
2022-08-31 00:06:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export type User = {
|
2022-08-31 02:11:36 +00:00
|
|
|
name: string;
|
|
|
|
email: string;
|
|
|
|
isSuperuser: boolean;
|
|
|
|
id: number;
|
2022-08-31 00:06:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export class UserApi extends BaseAPI {
|
2022-08-31 05:22:10 +00:00
|
|
|
locations: LocationsApi;
|
|
|
|
|
|
|
|
constructor(requests: Requests) {
|
|
|
|
super(requests);
|
|
|
|
|
|
|
|
this.locations = new LocationsApi(requests);
|
|
|
|
|
|
|
|
Object.freeze(this);
|
|
|
|
}
|
|
|
|
|
2022-08-31 02:11:36 +00:00
|
|
|
public self() {
|
2022-09-01 22:32:03 +00:00
|
|
|
return this.http.get<Result<User>>(UrlBuilder("/users/self"));
|
2022-08-31 02:11:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public logout() {
|
2022-09-01 22:32:03 +00:00
|
|
|
return this.http.post<object, void>(UrlBuilder("/users/logout"), {});
|
2022-08-31 02:11:36 +00:00
|
|
|
}
|
2022-08-31 00:06:57 +00:00
|
|
|
}
|