labels create and get

This commit is contained in:
Hayden 2022-09-01 17:52:40 -08:00
parent f956ec8eb2
commit 8ece3bd7bf
24 changed files with 850 additions and 132 deletions

View file

@ -0,0 +1,32 @@
import { BaseAPI, UrlBuilder } from '../base';
import { Details, OutType, Results } from './types';
export type LabelCreate = Details & {
color: string;
};
export type LabelUpdate = LabelCreate;
export type Label = LabelCreate & OutType;
export class LabelsApi extends BaseAPI {
async getAll() {
return this.http.get<Results<Label>>(UrlBuilder('/labels'));
}
async create(label: LabelCreate) {
return this.http.post<LabelCreate, Label>(UrlBuilder('/labels'), label);
}
async get(id: string) {
return this.http.get<Label>(UrlBuilder(`/labels/${id}`));
}
async delete(id: string) {
return this.http.delete<void>(UrlBuilder(`/labels/${id}`));
}
async update(id: string, label: LabelUpdate) {
return this.http.put<LabelUpdate, Label>(UrlBuilder(`/labels/${id}`), label);
}
}

View file

@ -1,17 +1,12 @@
import { BaseAPI, UrlBuilder } from '../base';
import { type Results } from '../base/base-types';
import { Details, OutType, Results } from './types';
export type LocationCreate = {
name: string;
description: string;
};
export type LocationCreate = Details;
export type Location = LocationCreate & {
id: string;
groupId: string;
createdAt: string;
updatedAt: string;
};
export type Location = LocationCreate &
OutType & {
groupId: string;
};
export type LocationUpdate = LocationCreate;

View file

@ -0,0 +1,19 @@
/**
* OutType is the base type that is returned from the API.
* In contains the common fields that are included with every
* API response that isn't a bulk result
*/
export type OutType = {
id: string;
createdAt: string;
updatedAt: string;
};
export type Details = {
name: string;
description: string;
};
export type Results<T> = {
items: T[];
};