mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 08:10:28 +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,
|
||||
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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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