diff --git a/frontend/lib/api/classes/items.ts b/frontend/lib/api/classes/items.ts index b7cc17d..1a49f26 100644 --- a/frontend/lib/api/classes/items.ts +++ b/frontend/lib/api/classes/items.ts @@ -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({ + 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); diff --git a/frontend/lib/api/types/data-contracts.ts b/frontend/lib/api/types/data-contracts.ts index 98fad70..a49fadf 100644 --- a/frontend/lib/api/types/data-contracts.ts +++ b/frontend/lib/api/types/data-contracts.ts @@ -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; diff --git a/frontend/lib/requests/requests.ts b/frontend/lib/requests/requests.ts index 32b79bc..8aecda1 100644 --- a/frontend/lib/requests/requests.ts +++ b/frontend/lib/requests/requests.ts @@ -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(Method.PUT, args); } + public patch(args: RequestArgs): Promise> { + return this.do(Method.PATCH, args); + } + public delete(args: RequestArgs): Promise> { return this.do(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(method: Method, rargs: RequestArgs): Promise> {