mirror of
https://github.com/hay-kot/homebox.git
synced 2025-08-03 08:10:28 +00:00
update item types and add attachments
This commit is contained in:
parent
4a5928a362
commit
3cae78a85e
1 changed files with 9 additions and 5 deletions
|
@ -1,17 +1,16 @@
|
||||||
import { BaseAPI, route } from "../base";
|
import { BaseAPI, route } from "../base";
|
||||||
import { parseDate } from "../base/base-api";
|
import { parseDate } from "../base/base-api";
|
||||||
import { ItemAttachmentToken, ItemCreate, ItemOut, ItemSummary, ItemUpdate } from "../types/data-contracts";
|
import { ItemAttachmentToken, ItemCreate, ItemOut, ItemSummary, ItemUpdate } from "../types/data-contracts";
|
||||||
|
import { AttachmentTypes } from "../types/non-generated";
|
||||||
import { Results } from "./types";
|
import { Results } from "./types";
|
||||||
|
|
||||||
export type AttachmentType = "photo" | "manual" | "warranty" | "attachment";
|
|
||||||
|
|
||||||
export class ItemsApi extends BaseAPI {
|
export class ItemsApi extends BaseAPI {
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.http.get<Results<ItemOut>>({ url: route("/items") });
|
return this.http.get<Results<ItemSummary>>({ url: route("/items") });
|
||||||
}
|
}
|
||||||
|
|
||||||
create(item: ItemCreate) {
|
create(item: ItemCreate) {
|
||||||
return this.http.post<ItemCreate, ItemSummary>({ url: route("/items"), body: item });
|
return this.http.post<ItemCreate, ItemOut>({ url: route("/items"), body: item });
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(id: string) {
|
async get(id: string) {
|
||||||
|
@ -53,10 +52,11 @@ export class ItemsApi extends BaseAPI {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addAttachment(id: string, file: File, type: AttachmentType) {
|
addAttachment(id: string, file: File | Blob, filename: string, type: AttachmentTypes) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
formData.append("type", type);
|
formData.append("type", type);
|
||||||
|
formData.append("name", filename);
|
||||||
|
|
||||||
return this.http.post<FormData, ItemOut>({
|
return this.http.post<FormData, ItemOut>({
|
||||||
url: route(`/items/${id}/attachments`),
|
url: route(`/items/${id}/attachments`),
|
||||||
|
@ -75,4 +75,8 @@ export class ItemsApi extends BaseAPI {
|
||||||
|
|
||||||
return route(`/items/${id}/attachments/download`, { token: payload.data.token });
|
return route(`/items/${id}/attachments/download`, { token: payload.data.token });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteAttachment(id: string, attachmentId: string) {
|
||||||
|
return this.http.delete<void>({ url: route(`/items/${id}/attachments/${attachmentId}`) });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue