forked from mirrors/homebox
3d295b5132
* location tree API * test fixes * initial tree location elements * locations tree page * update meta-data * code-gen * store item display preferences * introduce basic table/card view elements * codegen * set parent location during location creation * add item support for tree query * refactor tree view * wip: location selector improvements * type gen * rename items -> search * remove various log statements * fix markdown rendering for description * update location selectors * fix tests * fix currency tests * formatting
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { BaseAPI, route } from "../base";
|
|
import { LocationOutCount, LocationCreate, LocationOut, LocationUpdate, TreeItem } from "../types/data-contracts";
|
|
import { Results } from "../types/non-generated";
|
|
|
|
export type LocationsQuery = {
|
|
filterChildren: boolean;
|
|
};
|
|
|
|
export type TreeQuery = {
|
|
withItems: boolean;
|
|
};
|
|
|
|
export class LocationsApi extends BaseAPI {
|
|
getAll(q: LocationsQuery = { filterChildren: false }) {
|
|
return this.http.get<Results<LocationOutCount>>({ url: route("/locations", q) });
|
|
}
|
|
|
|
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 });
|
|
}
|
|
|
|
get(id: string) {
|
|
return this.http.get<LocationOut>({ url: route(`/locations/${id}`) });
|
|
}
|
|
|
|
delete(id: string) {
|
|
return this.http.delete<void>({ url: route(`/locations/${id}`) });
|
|
}
|
|
|
|
update(id: string, body: LocationUpdate) {
|
|
return this.http.put<LocationUpdate, LocationOut>({ url: route(`/locations/${id}`), body });
|
|
}
|
|
}
|