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

38 lines
914 B
TypeScript
Raw Normal View History

2022-09-05 00:55:52 +00:00
import { BaseAPI, route } from '../base';
2022-09-06 18:32:03 +00:00
import { Item } from './items';
2022-09-02 01:52:40 +00:00
import { Details, OutType, Results } from './types';
export type LabelCreate = Details & {
color: string;
};
export type LabelUpdate = LabelCreate;
2022-09-02 17:46:20 +00:00
export type Label = LabelCreate &
OutType & {
groupId: string;
2022-09-06 18:32:03 +00:00
items: Item[];
2022-09-02 17:46:20 +00:00
};
2022-09-02 01:52:40 +00:00
export class LabelsApi extends BaseAPI {
async getAll() {
2022-09-09 06:05:23 +00:00
return this.http.get<Results<Label>>({ url: route('/labels') });
2022-09-02 01:52:40 +00:00
}
2022-09-09 06:05:23 +00:00
async create(body: LabelCreate) {
return this.http.post<LabelCreate, Label>({ url: route('/labels'), body });
2022-09-02 01:52:40 +00:00
}
async get(id: string) {
2022-09-09 06:05:23 +00:00
return this.http.get<Label>({ url: route(`/labels/${id}`) });
2022-09-02 01:52:40 +00:00
}
async delete(id: string) {
2022-09-09 06:05:23 +00:00
return this.http.delete<void>({ url: route(`/labels/${id}`) });
2022-09-02 01:52:40 +00:00
}
2022-09-09 06:05:23 +00:00
async update(id: string, body: LabelUpdate) {
return this.http.put<LabelUpdate, Label>({ url: route(`/labels/${id}`), body });
2022-09-02 01:52:40 +00:00
}
}