homebox/frontend/lib/api/classes/locations.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

import { BaseAPI, route } from "../base";
import { LocationOutCount, LocationCreate, LocationOut, LocationUpdate, TreeItem } from "../types/data-contracts";
import { Results } from "../types/non-generated";
2022-08-31 05:22:10 +00:00
export type LocationsQuery = {
filterChildren: boolean;
};
export type TreeQuery = {
withItems: boolean;
};
2022-08-31 05:22:10 +00:00
export class LocationsApi extends BaseAPI {
getAll(q: LocationsQuery = { filterChildren: false }) {
return this.http.get<Results<LocationOutCount>>({ url: route("/locations", q) });
2022-08-31 05:22:10 +00:00
}
getTree(tq = { withItems: false }) {
return this.http.get<Results<TreeItem>>({ url: route("/locations/tree", tq) });
}
create(body: LocationCreate) {
return this.http.post<LocationCreate, LocationOut>({ url: route("/locations"), body });
2022-08-31 05:22:10 +00:00
}
2022-09-01 22:32:03 +00:00
get(id: string) {
return this.http.get<LocationOut>({ url: route(`/locations/${id}`) });
2022-09-01 22:32:03 +00:00
}
delete(id: string) {
2022-09-09 06:05:23 +00:00
return this.http.delete<void>({ url: route(`/locations/${id}`) });
2022-09-01 22:32:03 +00:00
}
update(id: string, body: LocationUpdate) {
return this.http.put<LocationUpdate, LocationOut>({ url: route(`/locations/${id}`), body });
2022-09-01 22:32:03 +00:00
}
2022-08-31 05:22:10 +00:00
}