From 3cae78a85eefcfe99cff3228968c9e68bf42ae8c Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Mon, 19 Sep 2022 21:34:31 -0800 Subject: [PATCH] update item types and add attachments --- frontend/lib/api/classes/items.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/frontend/lib/api/classes/items.ts b/frontend/lib/api/classes/items.ts index 99d3d43..8257eaf 100644 --- a/frontend/lib/api/classes/items.ts +++ b/frontend/lib/api/classes/items.ts @@ -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>({ url: route("/items") }); + return this.http.get>({ url: route("/items") }); } create(item: ItemCreate) { - return this.http.post({ url: route("/items"), body: item }); + return this.http.post({ 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({ 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({ url: route(`/items/${id}/attachments/${attachmentId}`) }); + } }