mirror of
https://github.com/hay-kot/homebox.git
synced 2024-12-20 22:06:31 +00:00
95ab14b866
* format readme * update logo * format html * add logo to docs * repository for document and document tokens * add attachments type and repository * autogenerate types via scripts * use autogenerated types * attachment type updates * add insured and quantity fields for items * implement HasID interface for entities * implement label updates for items * implement service update method * WIP item update client side actions * check err on attachment * finish types for basic items editor * remove unused var * house keeping
50 lines
1.4 KiB
TypeScript
50 lines
1.4 KiB
TypeScript
import { BaseAPI, route } from "../base";
|
|
import { parseDate } from "../base/base-api";
|
|
import { ItemCreate, ItemOut, ItemSummary, ItemUpdate } from "../types/data-contracts";
|
|
import { Results } from "./types";
|
|
|
|
export class ItemsApi extends BaseAPI {
|
|
getAll() {
|
|
return this.http.get<Results<ItemOut>>({ url: route("/items") });
|
|
}
|
|
|
|
create(item: ItemCreate) {
|
|
return this.http.post<ItemCreate, ItemSummary>({ url: route("/items"), body: item });
|
|
}
|
|
|
|
async get(id: string) {
|
|
const payload = await this.http.get<ItemOut>({ url: route(`/items/${id}`) });
|
|
|
|
if (!payload.data) {
|
|
return payload;
|
|
}
|
|
|
|
// Parse Date Types
|
|
payload.data = parseDate(payload.data, ["purchaseTime", "soldTime", "warrantyExpires"]);
|
|
return payload;
|
|
}
|
|
|
|
delete(id: string) {
|
|
return this.http.delete<void>({ url: route(`/items/${id}`) });
|
|
}
|
|
|
|
async update(id: string, item: ItemUpdate) {
|
|
const payload = await this.http.put<ItemCreate, ItemOut>({
|
|
url: route(`/items/${id}`),
|
|
body: this.dropFields(item),
|
|
});
|
|
if (!payload.data) {
|
|
return payload;
|
|
}
|
|
|
|
payload.data = parseDate(payload.data, ["purchaseTime", "soldTime", "warrantyExpires"]);
|
|
return payload;
|
|
}
|
|
|
|
import(file: File) {
|
|
const formData = new FormData();
|
|
formData.append("csv", file);
|
|
|
|
return this.http.post<FormData, void>({ url: route("/items/import"), data: formData });
|
|
}
|
|
}
|