mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-05 09:10:26 +00:00
new API class method for patch operations
This commit is contained in:
parent
f5daf96e1e
commit
00b60eb005
3 changed files with 26 additions and 1 deletions
|
@ -4,6 +4,7 @@ import {
|
||||||
ItemAttachmentUpdate,
|
ItemAttachmentUpdate,
|
||||||
ItemCreate,
|
ItemCreate,
|
||||||
ItemOut,
|
ItemOut,
|
||||||
|
ItemPatch,
|
||||||
ItemSummary,
|
ItemSummary,
|
||||||
ItemUpdate,
|
ItemUpdate,
|
||||||
MaintenanceEntry,
|
MaintenanceEntry,
|
||||||
|
@ -138,6 +139,20 @@ export class ItemsApi extends BaseAPI {
|
||||||
return payload;
|
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) {
|
import(file: File | Blob) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("csv", file);
|
formData.append("csv", file);
|
||||||
|
|
|
@ -119,6 +119,11 @@ export interface ItemOut {
|
||||||
warrantyExpires: Date | string;
|
warrantyExpires: Date | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ItemPatch {
|
||||||
|
id: string;
|
||||||
|
quantity: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
export interface ItemSummary {
|
export interface ItemSummary {
|
||||||
archived: boolean;
|
archived: boolean;
|
||||||
createdAt: Date | string;
|
createdAt: Date | string;
|
||||||
|
|
|
@ -3,6 +3,7 @@ export enum Method {
|
||||||
POST = "POST",
|
POST = "POST",
|
||||||
PUT = "PUT",
|
PUT = "PUT",
|
||||||
DELETE = "DELETE",
|
DELETE = "DELETE",
|
||||||
|
PATCH = "PATCH",
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ResponseInterceptor = (r: Response, rq?: RequestInit) => void;
|
export type ResponseInterceptor = (r: Response, rq?: RequestInit) => void;
|
||||||
|
@ -57,12 +58,16 @@ export class Requests {
|
||||||
return this.do<U>(Method.PUT, args);
|
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>> {
|
public delete<T>(args: RequestArgs<T>): Promise<TResponse<T>> {
|
||||||
return this.do<T>(Method.DELETE, args);
|
return this.do<T>(Method.DELETE, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
private methodSupportsBody(method: Method): boolean {
|
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>> {
|
private async do<T>(method: Method, rargs: RequestArgs<unknown>): Promise<TResponse<T>> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue