2022-09-09 14:46:53 -08:00
|
|
|
import { BaseAPI, route } from "./base";
|
|
|
|
import { ItemsApi } from "./classes/items";
|
|
|
|
import { LabelsApi } from "./classes/labels";
|
|
|
|
import { LocationsApi } from "./classes/locations";
|
|
|
|
import { Requests } from "~~/lib/requests";
|
2022-08-30 16:06:57 -08:00
|
|
|
|
|
|
|
export type Result<T> = {
|
2022-08-30 18:11:36 -08:00
|
|
|
item: T;
|
2022-08-30 16:06:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export type User = {
|
2022-08-30 18:11:36 -08:00
|
|
|
name: string;
|
|
|
|
email: string;
|
|
|
|
isSuperuser: boolean;
|
|
|
|
id: number;
|
2022-08-30 16:06:57 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
export class UserApi extends BaseAPI {
|
2022-08-30 21:22:10 -08:00
|
|
|
locations: LocationsApi;
|
2022-09-01 17:52:40 -08:00
|
|
|
labels: LabelsApi;
|
2022-09-03 01:17:57 -08:00
|
|
|
items: ItemsApi;
|
2022-08-30 21:22:10 -08:00
|
|
|
constructor(requests: Requests) {
|
|
|
|
super(requests);
|
|
|
|
|
|
|
|
this.locations = new LocationsApi(requests);
|
2022-09-01 17:52:40 -08:00
|
|
|
this.labels = new LabelsApi(requests);
|
2022-09-03 01:17:57 -08:00
|
|
|
this.items = new ItemsApi(requests);
|
2022-08-30 21:22:10 -08:00
|
|
|
|
|
|
|
Object.freeze(this);
|
|
|
|
}
|
|
|
|
|
2022-08-30 18:11:36 -08:00
|
|
|
public self() {
|
2022-09-09 14:46:53 -08:00
|
|
|
return this.http.get<Result<User>>({ url: route("/users/self") });
|
2022-08-30 18:11:36 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public logout() {
|
2022-09-09 14:46:53 -08:00
|
|
|
return this.http.post<object, void>({ url: route("/users/logout") });
|
2022-08-30 18:11:36 -08:00
|
|
|
}
|
2022-09-03 18:42:03 -08:00
|
|
|
|
|
|
|
public deleteAccount() {
|
2022-09-09 14:46:53 -08:00
|
|
|
return this.http.delete<void>({ url: route("/users/self") });
|
2022-09-03 18:42:03 -08:00
|
|
|
}
|
2022-08-30 16:06:57 -08:00
|
|
|
}
|