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

36 lines
822 B
TypeScript
Raw Normal View History

2022-09-05 00:55:52 +00:00
import { BaseAPI, route } from '../base';
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-02 01:52:40 +00:00
export class LabelsApi extends BaseAPI {
async getAll() {
2022-09-05 00:55:52 +00:00
return this.http.get<Results<Label>>(route('/labels'));
2022-09-02 01:52:40 +00:00
}
async create(label: LabelCreate) {
2022-09-05 00:55:52 +00:00
return this.http.post<LabelCreate, Label>(route('/labels'), label);
2022-09-02 01:52:40 +00:00
}
async get(id: string) {
2022-09-05 00:55:52 +00:00
return this.http.get<Label>(route(`/labels/${id}`));
2022-09-02 01:52:40 +00:00
}
async delete(id: string) {
2022-09-05 00:55:52 +00:00
return this.http.delete<void>(route(`/labels/${id}`));
2022-09-02 01:52:40 +00:00
}
async update(id: string, label: LabelUpdate) {
2022-09-05 00:55:52 +00:00
return this.http.put<LabelUpdate, Label>(route(`/labels/${id}`), label);
2022-09-02 01:52:40 +00:00
}
}