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

36 lines
970 B
TypeScript
Raw Normal View History

2022-09-05 00:55:52 +00:00
import { BaseAPI, route } from '../base';
2022-09-03 09:17:57 +00:00
import { Item } from './items';
2022-09-02 01:52:40 +00:00
import { Details, OutType, Results } from './types';
2022-08-31 05:22:10 +00:00
2022-09-02 01:52:40 +00:00
export type LocationCreate = Details;
2022-08-31 05:22:10 +00:00
2022-09-02 01:52:40 +00:00
export type Location = LocationCreate &
OutType & {
groupId: string;
2022-09-03 09:17:57 +00:00
items: Item[];
itemCount: number;
2022-09-02 01:52:40 +00:00
};
2022-08-31 05:22:10 +00:00
2022-09-01 22:32:03 +00:00
export type LocationUpdate = LocationCreate;
2022-08-31 05:22:10 +00:00
export class LocationsApi extends BaseAPI {
async getAll() {
2022-09-09 06:05:23 +00:00
return this.http.get<Results<Location>>({ url: route('/locations') });
2022-08-31 05:22:10 +00:00
}
2022-09-09 06:05:23 +00:00
async create(body: LocationCreate) {
return this.http.post<LocationCreate, Location>({ url: route('/locations'), body });
2022-08-31 05:22:10 +00:00
}
2022-09-01 22:32:03 +00:00
async get(id: string) {
2022-09-09 06:05:23 +00:00
return this.http.get<Location>({ url: route(`/locations/${id}`) });
2022-09-01 22:32:03 +00:00
}
async 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
}
2022-09-09 06:05:23 +00:00
async update(id: string, body: LocationUpdate) {
return this.http.put<LocationUpdate, Location>({ url: route(`/locations/${id}`), body });
2022-09-01 22:32:03 +00:00
}
2022-08-31 05:22:10 +00:00
}