From 86b878022aac041916cb238308eabddbd7af063c Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Sat, 15 Oct 2022 19:38:33 -0800 Subject: [PATCH] add receipt support for attachments --- backend/ent/attachment/attachment.go | 3 ++- backend/ent/migrate/schema.go | 2 +- backend/ent/schema/attachment.go | 2 +- frontend/lib/api/types/non-generated.ts | 1 + frontend/pages/item/[id]/edit.vue | 2 ++ frontend/pages/item/[id]/index.vue | 16 ++++++++++++++++ 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/backend/ent/attachment/attachment.go b/backend/ent/attachment/attachment.go index d2775e2..f7aef63 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 nil default: 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.go index 7954764..901b3bd 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.go index 4a13ba8..7dc27d3 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.ts index e248ab1..acb7e01 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 = { diff --git a/frontend/pages/item/[id]/edit.vue b/frontend/pages/item/[id]/edit.vue index 522e406..c5cfb53 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 @@ Warranty Manual Attachment + Receipt