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

36 lines
971 B
TypeScript
Raw Normal View History

2022-08-30 21:22:10 -08:00
import { BaseAPI, UrlBuilder } from '../base';
2022-09-03 01:17:57 -08:00
import { Item } from './items';
2022-09-01 17:52:40 -08:00
import { Details, OutType, Results } from './types';
2022-08-30 21:22:10 -08:00
2022-09-01 17:52:40 -08:00
export type LocationCreate = Details;
2022-08-30 21:22:10 -08:00
2022-09-01 17:52:40 -08:00
export type Location = LocationCreate &
OutType & {
groupId: string;
2022-09-03 01:17:57 -08:00
items: Item[];
itemCount: number;
2022-09-01 17:52:40 -08:00
};
2022-08-30 21:22:10 -08:00
2022-09-01 14:32:03 -08:00
export type LocationUpdate = LocationCreate;
2022-08-30 21:22:10 -08:00
export class LocationsApi extends BaseAPI {
async getAll() {
return this.http.get<Results<Location>>(UrlBuilder('/locations'));
}
async create(location: LocationCreate) {
return this.http.post<LocationCreate, Location>(UrlBuilder('/locations'), location);
}
2022-09-01 14:32:03 -08:00
async get(id: string) {
return this.http.get<Location>(UrlBuilder(`/locations/${id}`));
}
async delete(id: string) {
return this.http.delete<void>(UrlBuilder(`/locations/${id}`));
}
async update(id: string, location: LocationUpdate) {
return this.http.put<LocationUpdate, Location>(UrlBuilder(`/locations/${id}`), location);
}
2022-08-30 21:22:10 -08:00
}