forked from mirrors/homebox
feat: easily increment quantity (#473)
* fix vue version issue * new patch API endpoint * doc-gen * new API class method for patch operations * add quantity patch UI support * fix typegen errors * fix ts errors
This commit is contained in:
parent
4dd036abb2
commit
ef1531e561
16 changed files with 353 additions and 163 deletions
|
@ -4,6 +4,7 @@ import {
|
|||
ItemAttachmentUpdate,
|
||||
ItemCreate,
|
||||
ItemOut,
|
||||
ItemPatch,
|
||||
ItemSummary,
|
||||
ItemUpdate,
|
||||
MaintenanceEntry,
|
||||
|
@ -138,6 +139,20 @@ export class ItemsApi extends BaseAPI {
|
|||
return payload;
|
||||
}
|
||||
|
||||
async patch(id: string, item: ItemPatch) {
|
||||
const resp = await this.http.patch<ItemPatch, ItemOut>({
|
||||
url: route(`/items/${id}`),
|
||||
body: this.dropFields(item),
|
||||
});
|
||||
|
||||
if (!resp.data) {
|
||||
return resp;
|
||||
}
|
||||
|
||||
resp.data = parseDate(resp.data, ["purchaseTime", "soldTime", "warrantyExpires"]);
|
||||
return resp;
|
||||
}
|
||||
|
||||
import(file: File | Blob) {
|
||||
const formData = new FormData();
|
||||
formData.append("csv", file);
|
||||
|
|
|
@ -67,7 +67,7 @@ export interface ItemCreate {
|
|||
* @maxLength 255
|
||||
*/
|
||||
name: string;
|
||||
parentId: string | null;
|
||||
parentId?: string | null;
|
||||
}
|
||||
|
||||
export interface ItemField {
|
||||
|
@ -94,13 +94,13 @@ export interface ItemOut {
|
|||
/** Warranty */
|
||||
lifetimeWarranty: boolean;
|
||||
/** Edges */
|
||||
location: LocationSummary | null;
|
||||
location?: LocationSummary | null;
|
||||
manufacturer: string;
|
||||
modelNumber: string;
|
||||
name: string;
|
||||
/** Extras */
|
||||
notes: string;
|
||||
parent: ItemSummary | null;
|
||||
parent?: ItemSummary | null;
|
||||
purchaseFrom: string;
|
||||
/** @example "0" */
|
||||
purchasePrice: string;
|
||||
|
@ -119,6 +119,11 @@ export interface ItemOut {
|
|||
warrantyExpires: Date | string;
|
||||
}
|
||||
|
||||
export interface ItemPatch {
|
||||
id: string;
|
||||
quantity?: number | null;
|
||||
}
|
||||
|
||||
export interface ItemSummary {
|
||||
archived: boolean;
|
||||
createdAt: Date | string;
|
||||
|
@ -127,7 +132,7 @@ export interface ItemSummary {
|
|||
insured: boolean;
|
||||
labels: LabelSummary[];
|
||||
/** Edges */
|
||||
location: LocationSummary | null;
|
||||
location?: LocationSummary | null;
|
||||
name: string;
|
||||
/** @example "0" */
|
||||
purchasePrice: string;
|
||||
|
@ -152,7 +157,7 @@ export interface ItemUpdate {
|
|||
name: string;
|
||||
/** Extras */
|
||||
notes: string;
|
||||
parentId: string | null;
|
||||
parentId?: string | null;
|
||||
purchaseFrom: string;
|
||||
/** @example "0" */
|
||||
purchasePrice: string;
|
||||
|
@ -203,7 +208,7 @@ export interface LabelSummary {
|
|||
export interface LocationCreate {
|
||||
description: string;
|
||||
name: string;
|
||||
parentId: string | null;
|
||||
parentId?: string | null;
|
||||
}
|
||||
|
||||
export interface LocationOut {
|
||||
|
@ -238,7 +243,7 @@ export interface LocationUpdate {
|
|||
description: string;
|
||||
id: string;
|
||||
name: string;
|
||||
parentId: string | null;
|
||||
parentId?: string | null;
|
||||
}
|
||||
|
||||
export interface MaintenanceEntry {
|
||||
|
@ -309,7 +314,7 @@ export interface NotifierUpdate {
|
|||
* @maxLength 255
|
||||
*/
|
||||
name: string;
|
||||
url: string | null;
|
||||
url?: string | null;
|
||||
}
|
||||
|
||||
export interface PaginationResultItemSummary {
|
||||
|
|
|
@ -3,6 +3,7 @@ export enum Method {
|
|||
POST = "POST",
|
||||
PUT = "PUT",
|
||||
DELETE = "DELETE",
|
||||
PATCH = "PATCH",
|
||||
}
|
||||
|
||||
export type ResponseInterceptor = (r: Response, rq?: RequestInit) => void;
|
||||
|
@ -57,12 +58,16 @@ export class Requests {
|
|||
return this.do<U>(Method.PUT, args);
|
||||
}
|
||||
|
||||
public patch<T, U>(args: RequestArgs<T>): Promise<TResponse<U>> {
|
||||
return this.do<U>(Method.PATCH, args);
|
||||
}
|
||||
|
||||
public delete<T>(args: RequestArgs<T>): Promise<TResponse<T>> {
|
||||
return this.do<T>(Method.DELETE, args);
|
||||
}
|
||||
|
||||
private methodSupportsBody(method: Method): boolean {
|
||||
return method === Method.POST || method === Method.PUT;
|
||||
return method === Method.POST || method === Method.PUT || method === Method.PATCH;
|
||||
}
|
||||
|
||||
private async do<T>(method: Method, rargs: RequestArgs<unknown>): Promise<TResponse<T>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue