update item types and add attachments

This commit is contained in:
Hayden 2022-09-19 21:34:31 -08:00
parent 4a5928a362
commit 3cae78a85e

View file

@ -1,17 +1,16 @@
import { BaseAPI, route } from "../base";
import { parseDate } from "../base/base-api";
import { ItemAttachmentToken, ItemCreate, ItemOut, ItemSummary, ItemUpdate } from "../types/data-contracts";
import { AttachmentTypes } from "../types/non-generated";
import { Results } from "./types";
export type AttachmentType = "photo" | "manual" | "warranty" | "attachment";
export class ItemsApi extends BaseAPI {
getAll() {
return this.http.get<Results<ItemOut>>({ url: route("/items") });
return this.http.get<Results<ItemSummary>>({ url: route("/items") });
}
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) {
@ -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();
formData.append("file", file);
formData.append("type", type);
formData.append("name", filename);
return this.http.post<FormData, ItemOut>({
url: route(`/items/${id}/attachments`),
@ -75,4 +75,8 @@ export class ItemsApi extends BaseAPI {
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}`) });
}
}