A continuation of HomeBox the inventory and organization system built for the Home User
feat: add receipt support for attachments (#89)
Hayden57f9372e4905
diff --git a/backend/ent/attachment/attachment.go b/backend/ent/attachment/attachment.goindex d2775e25..f7aef63c 100644--- a/backend/ent/attachment/attachment.go+++ b/backend/ent/attachment/attachment.go@@ -95,6 +95,7 @@ const (TypeManual Type = "manual"TypeWarranty Type = "warranty"TypeAttachment Type = "attachment"+ TypeReceipt Type = "receipt")func (_type Type) String() string {@@ -104,7 +105,7 @@ func (_type Type) String() string {// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.func TypeValidator(_type Type) error {switch _type {- case TypePhoto, TypeManual, TypeWarranty, TypeAttachment:+ case TypePhoto, TypeManual, TypeWarranty, TypeAttachment, TypeReceipt:return nildefault:return fmt.Errorf("attachment: invalid enum value for type field: %q", _type)diff --git a/backend/ent/migrate/schema.go b/backend/ent/migrate/schema.goindex 79547643..901b3bd7 100644--- a/backend/ent/migrate/schema.go+++ b/backend/ent/migrate/schema.go@@ -13,7 +13,7 @@ var ({Name: "id", Type: field.TypeUUID},{Name: "created_at", Type: field.TypeTime},{Name: "updated_at", Type: field.TypeTime},- {Name: "type", Type: field.TypeEnum, Enums: []string{"photo", "manual", "warranty", "attachment"}, Default: "attachment"},+ {Name: "type", Type: field.TypeEnum, Enums: []string{"photo", "manual", "warranty", "attachment", "receipt"}, Default: "attachment"},{Name: "document_attachments", Type: field.TypeUUID},{Name: "item_attachments", Type: field.TypeUUID},}diff --git a/backend/ent/schema/attachment.go b/backend/ent/schema/attachment.goindex 4a13ba82..7dc27d31 100644--- a/backend/ent/schema/attachment.go+++ b/backend/ent/schema/attachment.go@@ -22,7 +22,7 @@ func (Attachment) Mixin() []ent.Mixin {func (Attachment) Fields() []ent.Field {return []ent.Field{field.Enum("type").- Values("photo", "manual", "warranty", "attachment").+ Values("photo", "manual", "warranty", "attachment", "receipt").Default("attachment"),}}diff --git a/frontend/lib/api/types/non-generated.ts b/frontend/lib/api/types/non-generated.tsindex e248ab11..acb7e019 100644--- a/frontend/lib/api/types/non-generated.ts+++ b/frontend/lib/api/types/non-generated.ts@@ -3,6 +3,7 @@ export enum AttachmentTypes {Manual = "manual",Warranty = "warranty",Attachment = "attachment",+ Receipt = "receipt",}export type Result<T> = {diff --git a/frontend/pages/item/[id]/edit.vue b/frontend/pages/item/[id]/edit.vueindex 522e406d..c5cfb537 100644--- a/frontend/pages/item/[id]/edit.vue+++ b/frontend/pages/item/[id]/edit.vue@@ -190,6 +190,7 @@const dropAttachment = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Attachment);const dropWarranty = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Warranty);const dropManual = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Manual);+ const dropReceipt = (files: File[] | null) => uploadAttachment(files, AttachmentTypes.Receipt);async function uploadAttachment(files: File[] | null, type: AttachmentTypes) {if (!files && files.length === 0) {@@ -378,6 +379,7 @@<DropZone @drop="dropWarranty"> Warranty </DropZone><DropZone @drop="dropManual"> Manual </DropZone><DropZone @drop="dropAttachment"> Attachment </DropZone>+ <DropZone @drop="dropReceipt"> Receipt </DropZone></div><buttonv-elsediff --git a/frontend/pages/item/[id]/index.vue b/frontend/pages/item/[id]/index.vueindex 32145abe..b263801d 100644--- a/frontend/pages/item/[id]/index.vue+++ b/frontend/pages/item/[id]/index.vue@@ -31,6 +31,7 @@attachments: ItemAttachment[];warranty: ItemAttachment[];manuals: ItemAttachment[];+ receipts: ItemAttachment[];};const attachments = computed<FilteredAttachments>(() => {@@ -40,6 +41,7 @@attachments: [],manuals: [],warranty: [],+ receipts: [],};}@@ -51,6 +53,8 @@acc.warranty.push(attachment);} else if (attachment.type === "manual") {acc.manuals.push(attachment);+ } else if (attachment.type === "receipt") {+ acc.receipts.push(attachment);} else {acc.attachments.push(attachment);}@@ -61,6 +65,7 @@attachments: [] as ItemAttachment[],warranty: [] as ItemAttachment[],manuals: [] as ItemAttachment[],+ receipts: [] as ItemAttachment[],});});@@ -103,7 +108,8 @@attachments.value.photos.length > 0 ||attachments.value.attachments.length > 0 ||attachments.value.warranty.length > 0 ||- attachments.value.manuals.length > 0+ attachments.value.manuals.length > 0 ||+ attachments.value.receipts.length > 0);});@@ -134,6 +140,10 @@push("Manuals");}+ if (attachments.value.receipts.length > 0) {+ push("Receipts");+ }+return details;});@@ -323,6 +333,13 @@:item-id="item.id"/></template>+ <template #receipts>+ <ItemAttachmentsList+ v-if="attachments.receipts.length > 0"+ :attachments="attachments.receipts"+ :item-id="item.id"+ />+ </template></DetailsSection></BaseCard>