mirror of
https://github.com/hay-kot/homebox.git
synced 2025-05-24 14:12:32 +00:00
feat: items-editor (#5)
* 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
This commit is contained in:
parent
fbc364dcd2
commit
95ab14b866
125 changed files with 15626 additions and 1791 deletions
|
@ -1,60 +1,26 @@
|
|||
import { BaseAPI, route } from "../base";
|
||||
import { Label } from "./labels";
|
||||
import { Location } from "./locations";
|
||||
import { parseDate } from "../base/base-api";
|
||||
import { ItemCreate, ItemOut, ItemSummary, ItemUpdate } from "../types/data-contracts";
|
||||
import { Results } from "./types";
|
||||
|
||||
export interface ItemCreate {
|
||||
name: string;
|
||||
description: string;
|
||||
locationId: string;
|
||||
labelIds: string[];
|
||||
}
|
||||
|
||||
export interface Item {
|
||||
createdAt: string;
|
||||
description: string;
|
||||
id: string;
|
||||
labels: Label[];
|
||||
location: Location;
|
||||
manufacturer: string;
|
||||
modelNumber: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
purchaseFrom: string;
|
||||
purchasePrice: number;
|
||||
purchaseTime: Date;
|
||||
serialNumber: string;
|
||||
soldNotes: string;
|
||||
soldPrice: number;
|
||||
soldTime: Date;
|
||||
soldTo: string;
|
||||
updatedAt: string;
|
||||
lifetimeWarranty: boolean;
|
||||
warrantyExpires: Date;
|
||||
warrantyDetails: string;
|
||||
}
|
||||
|
||||
export class ItemsApi extends BaseAPI {
|
||||
getAll() {
|
||||
return this.http.get<Results<Item>>({ url: route("/items") });
|
||||
return this.http.get<Results<ItemOut>>({ url: route("/items") });
|
||||
}
|
||||
|
||||
create(item: ItemCreate) {
|
||||
return this.http.post<ItemCreate, Item>({ url: route("/items"), body: item });
|
||||
return this.http.post<ItemCreate, ItemSummary>({ url: route("/items"), body: item });
|
||||
}
|
||||
|
||||
async get(id: string) {
|
||||
const payload = await this.http.get<Item>({ url: route(`/items/${id}`) });
|
||||
const payload = await this.http.get<ItemOut>({ url: route(`/items/${id}`) });
|
||||
|
||||
if (!payload.data) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
// Parse Date Types
|
||||
payload.data.purchaseTime = new Date(payload.data.purchaseTime);
|
||||
payload.data.soldTime = new Date(payload.data.soldTime);
|
||||
payload.data.warrantyExpires = new Date(payload.data.warrantyExpires);
|
||||
|
||||
payload.data = parseDate(payload.data, ["purchaseTime", "soldTime", "warrantyExpires"]);
|
||||
return payload;
|
||||
}
|
||||
|
||||
|
@ -62,8 +28,17 @@ export class ItemsApi extends BaseAPI {
|
|||
return this.http.delete<void>({ url: route(`/items/${id}`) });
|
||||
}
|
||||
|
||||
update(id: string, item: ItemCreate) {
|
||||
return this.http.put<ItemCreate, Item>({ url: route(`/items/${id}`), body: item });
|
||||
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) {
|
||||
|
|
|
@ -1,37 +1,25 @@
|
|||
import { BaseAPI, route } from "../base";
|
||||
import { Item } from "./items";
|
||||
import { Details, OutType, Results } from "./types";
|
||||
|
||||
export type LabelCreate = Details & {
|
||||
color: string;
|
||||
};
|
||||
|
||||
export type LabelUpdate = LabelCreate;
|
||||
|
||||
export type Label = LabelCreate &
|
||||
OutType & {
|
||||
groupId: string;
|
||||
items: Item[];
|
||||
};
|
||||
import { LabelCreate, LabelOut } from "../types/data-contracts";
|
||||
import { Results } from "./types";
|
||||
|
||||
export class LabelsApi extends BaseAPI {
|
||||
getAll() {
|
||||
return this.http.get<Results<Label>>({ url: route("/labels") });
|
||||
return this.http.get<Results<LabelOut>>({ url: route("/labels") });
|
||||
}
|
||||
|
||||
create(body: LabelCreate) {
|
||||
return this.http.post<LabelCreate, Label>({ url: route("/labels"), body });
|
||||
return this.http.post<LabelCreate, LabelOut>({ url: route("/labels"), body });
|
||||
}
|
||||
|
||||
get(id: string) {
|
||||
return this.http.get<Label>({ url: route(`/labels/${id}`) });
|
||||
return this.http.get<LabelOut>({ url: route(`/labels/${id}`) });
|
||||
}
|
||||
|
||||
delete(id: string) {
|
||||
return this.http.delete<void>({ url: route(`/labels/${id}`) });
|
||||
}
|
||||
|
||||
update(id: string, body: LabelUpdate) {
|
||||
return this.http.put<LabelUpdate, Label>({ url: route(`/labels/${id}`), body });
|
||||
update(id: string, body: LabelCreate) {
|
||||
return this.http.put<LabelCreate, LabelOut>({ url: route(`/labels/${id}`), body });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,29 +1,20 @@
|
|||
import { BaseAPI, route } from "../base";
|
||||
import { Item } from "./items";
|
||||
import { Details, OutType, Results } from "./types";
|
||||
|
||||
export type LocationCreate = Details;
|
||||
|
||||
export type Location = LocationCreate &
|
||||
OutType & {
|
||||
groupId: string;
|
||||
items: Item[];
|
||||
itemCount: number;
|
||||
};
|
||||
import { LocationCount, LocationCreate, LocationOut } from "../types/data-contracts";
|
||||
import { Results } from "./types";
|
||||
|
||||
export type LocationUpdate = LocationCreate;
|
||||
|
||||
export class LocationsApi extends BaseAPI {
|
||||
getAll() {
|
||||
return this.http.get<Results<Location>>({ url: route("/locations") });
|
||||
return this.http.get<Results<LocationCount>>({ url: route("/locations") });
|
||||
}
|
||||
|
||||
create(body: LocationCreate) {
|
||||
return this.http.post<LocationCreate, Location>({ url: route("/locations"), body });
|
||||
return this.http.post<LocationCreate, LocationOut>({ url: route("/locations"), body });
|
||||
}
|
||||
|
||||
get(id: string) {
|
||||
return this.http.get<Location>({ url: route(`/locations/${id}`) });
|
||||
return this.http.get<LocationOut>({ url: route(`/locations/${id}`) });
|
||||
}
|
||||
|
||||
delete(id: string) {
|
||||
|
@ -31,6 +22,6 @@ export class LocationsApi extends BaseAPI {
|
|||
}
|
||||
|
||||
update(id: string, body: LocationUpdate) {
|
||||
return this.http.put<LocationUpdate, Location>({ url: route(`/locations/${id}`), body });
|
||||
return this.http.put<LocationUpdate, LocationOut>({ url: route(`/locations/${id}`), body });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,3 @@
|
|||
/**
|
||||
* 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[];
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue