2022-09-09 14:46:53 -08:00
|
|
|
import { BaseAPI, route } from "../base";
|
2023-01-28 11:53:00 -09:00
|
|
|
import { LocationOutCount, LocationCreate, LocationOut, LocationUpdate, TreeItem } from "../types/data-contracts";
|
2022-10-12 21:13:07 -08:00
|
|
|
import { Results } from "../types/non-generated";
|
2022-08-30 21:22:10 -08:00
|
|
|
|
2022-11-02 11:54:43 -08:00
|
|
|
export type LocationsQuery = {
|
|
|
|
filterChildren: boolean;
|
|
|
|
};
|
|
|
|
|
2023-01-28 11:53:00 -09:00
|
|
|
export type TreeQuery = {
|
|
|
|
withItems: boolean;
|
|
|
|
};
|
|
|
|
|
2022-08-30 21:22:10 -08:00
|
|
|
export class LocationsApi extends BaseAPI {
|
2022-11-02 11:54:43 -08:00
|
|
|
getAll(q: LocationsQuery = { filterChildren: false }) {
|
|
|
|
return this.http.get<Results<LocationOutCount>>({ url: route("/locations", q) });
|
2022-08-30 21:22:10 -08:00
|
|
|
}
|
|
|
|
|
2023-01-28 11:53:00 -09:00
|
|
|
getTree(tq = { withItems: false }) {
|
|
|
|
return this.http.get<Results<TreeItem>>({ url: route("/locations/tree", tq) });
|
|
|
|
}
|
|
|
|
|
2022-09-09 14:46:53 -08:00
|
|
|
create(body: LocationCreate) {
|
2022-09-12 14:47:27 -08:00
|
|
|
return this.http.post<LocationCreate, LocationOut>({ url: route("/locations"), body });
|
2022-08-30 21:22:10 -08:00
|
|
|
}
|
2022-09-01 14:32:03 -08:00
|
|
|
|
2022-09-09 14:46:53 -08:00
|
|
|
get(id: string) {
|
2022-09-12 14:47:27 -08:00
|
|
|
return this.http.get<LocationOut>({ url: route(`/locations/${id}`) });
|
2022-09-01 14:32:03 -08:00
|
|
|
}
|
2022-09-09 14:46:53 -08:00
|
|
|
|
|
|
|
delete(id: string) {
|
2022-09-08 22:05:23 -08:00
|
|
|
return this.http.delete<void>({ url: route(`/locations/${id}`) });
|
2022-09-01 14:32:03 -08:00
|
|
|
}
|
|
|
|
|
2022-09-09 14:46:53 -08:00
|
|
|
update(id: string, body: LocationUpdate) {
|
2022-09-12 14:47:27 -08:00
|
|
|
return this.http.put<LocationUpdate, LocationOut>({ url: route(`/locations/${id}`), body });
|
2022-09-01 14:32:03 -08:00
|
|
|
}
|
2022-08-30 21:22:10 -08:00
|
|
|
}
|