A continuation of HomeBox the inventory and organization system built for the Home User
fix: templates that dont have a location set (#1160)
Tonya2638f218f353
diff --git a/backend/internal/data/repo/repo_item_templates.go b/backend/internal/data/repo/repo_item_templates.goindex 532c6fe5..6b9eba03 100644--- a/backend/internal/data/repo/repo_item_templates.go+++ b/backend/internal/data/repo/repo_item_templates.go@@ -53,7 +53,7 @@ type (DefaultWarrantyDetails *string `json:"defaultWarrantyDetails,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"`// Default location and labels- DefaultLocationID *uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"`+ DefaultLocationID uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"`DefaultLabelIDs *[]uuid.UUID `json:"defaultLabelIds,omitempty" extensions:"x-nullable"`// Metadata flags@@ -82,7 +82,7 @@ type (DefaultWarrantyDetails *string `json:"defaultWarrantyDetails,omitempty" extensions:"x-nullable" validate:"omitempty,max=1000"`// Default location and labels- DefaultLocationID *uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"`+ DefaultLocationID uuid.UUID `json:"defaultLocationId,omitempty" extensions:"x-nullable"`DefaultLabelIDs *[]uuid.UUID `json:"defaultLabelIds,omitempty" extensions:"x-nullable"`// Metadata flags@@ -262,6 +262,7 @@ func (r *ItemTemplatesRepository) GetOne(ctx context.Context, gid uuid.UUID, id// Create creates a new templatefunc (r *ItemTemplatesRepository) Create(ctx context.Context, gid uuid.UUID, data ItemTemplateCreate) (ItemTemplateOut, error) {+ // Set up create builderq := r.db.ItemTemplate.Create().SetName(data.Name).SetDescription(data.Description).@@ -277,9 +278,12 @@ func (r *ItemTemplatesRepository) Create(ctx context.Context, gid uuid.UUID, datSetIncludeWarrantyFields(data.IncludeWarrantyFields).SetIncludePurchaseFields(data.IncludePurchaseFields).SetIncludeSoldFields(data.IncludeSoldFields).- SetGroupID(gid).- SetNillableLocationID(data.DefaultLocationID)+ SetGroupID(gid)+ // If a default location was provided (uuid != Nil) set it, otherwise leave empty+ if data.DefaultLocationID != uuid.Nil {+ q.SetLocationID(data.DefaultLocationID)+ }// Set default label IDs (stored as JSON)if data.DefaultLabelIDs != nil && len(*data.DefaultLabelIDs) > 0 {q.SetDefaultLabelIds(*data.DefaultLabelIDs)@@ -340,9 +344,9 @@ func (r *ItemTemplatesRepository) Update(ctx context.Context, gid uuid.UUID, datSetIncludePurchaseFields(data.IncludePurchaseFields).SetIncludeSoldFields(data.IncludeSoldFields)- // Update location- if data.DefaultLocationID != nil {- updateQ.SetLocationID(*data.DefaultLocationID)+ // Update location: set when provided (not uuid.Nil), otherwise clear+ if data.DefaultLocationID != uuid.Nil {+ updateQ.SetLocationID(data.DefaultLocationID)} else {updateQ.ClearLocation()}diff --git a/backend/internal/data/repo/repo_item_templates_test.go b/backend/internal/data/repo/repo_item_templates_test.goindex dab5627d..4f6e6cfb 100644--- a/backend/internal/data/repo/repo_item_templates_test.go+++ b/backend/internal/data/repo/repo_item_templates_test.go@@ -249,7 +249,7 @@ func TestItemTemplatesRepository_CreateWithLocation(t *testing.T) {// Create template with locationdata := templateFactory()- data.DefaultLocationID = &loc.ID+ data.DefaultLocationID = loc.IDtemplate, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data)require.NoError(t, err)@@ -311,7 +311,7 @@ func TestItemTemplatesRepository_UpdateRemoveLocation(t *testing.T) {// Create template with locationdata := templateFactory()- data.DefaultLocationID = &loc.ID+ data.DefaultLocationID = loc.IDtemplate, err := tRepos.ItemTemplates.Create(context.Background(), tGroup.ID, data)require.NoError(t, err)@@ -323,7 +323,7 @@ func TestItemTemplatesRepository_UpdateRemoveLocation(t *testing.T) {ID: template.ID,Name: template.Name,DefaultQuantity: &qty,- DefaultLocationID: nil, // Remove location+ DefaultLocationID: uuid.Nil, // Remove location}updated, err := tRepos.ItemTemplates.Update(context.Background(), tGroup.ID, updateData)diff --git a/frontend/components/Template/Card.vue b/frontend/components/Template/Card.vueindex 080e0f77..f9eb179c 100644--- a/frontend/components/Template/Card.vue+++ b/frontend/components/Template/Card.vue@@ -58,7 +58,7 @@defaultModelNumber: fullTemplate.defaultModelNumber,defaultLifetimeWarranty: fullTemplate.defaultLifetimeWarranty,defaultWarrantyDetails: fullTemplate.defaultWarrantyDetails,- defaultLocationId: fullTemplate.defaultLocation?.id ?? "",+ defaultLocationId: fullTemplate.defaultLocation?.id ?? null,defaultLabelIds: fullTemplate.defaultLabels?.map(l => l.id) || [],includeWarrantyFields: fullTemplate.includeWarrantyFields,includePurchaseFields: fullTemplate.includePurchaseFields,diff --git a/frontend/pages/template/[id].vue b/frontend/pages/template/[id].vueindex 78abc1e9..ff2cf77d 100644--- a/frontend/pages/template/[id].vue+++ b/frontend/pages/template/[id].vue@@ -119,7 +119,7 @@// Prepare the data with proper format for APIconst payload = {...updateData,- defaultLocationId: updateData.defaultLocation?.id ?? "",+ defaultLocationId: updateData.defaultLocation?.id ?? null,};const { error, data } = await api.templates.update(templateId.value, payload);