mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-24 06:28:34 +01:00
Compare commits
1 Commits
main
...
tonya/fix-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b479bb842e |
@@ -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 template
|
||||
func (r *ItemTemplatesRepository) Create(ctx context.Context, gid uuid.UUID, data ItemTemplateCreate) (ItemTemplateOut, error) {
|
||||
// Set up create builder
|
||||
q := r.db.ItemTemplate.Create().
|
||||
SetName(data.Name).
|
||||
SetDescription(data.Description).
|
||||
@@ -277,9 +278,12 @@ func (r *ItemTemplatesRepository) Create(ctx context.Context, gid uuid.UUID, dat
|
||||
SetIncludeWarrantyFields(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, dat
|
||||
SetIncludePurchaseFields(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()
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func TestItemTemplatesRepository_CreateWithLocation(t *testing.T) {
|
||||
|
||||
// Create template with location
|
||||
data := templateFactory()
|
||||
data.DefaultLocationID = &loc.ID
|
||||
data.DefaultLocationID = loc.ID
|
||||
|
||||
template, 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 location
|
||||
data := templateFactory()
|
||||
data.DefaultLocationID = &loc.ID
|
||||
data.DefaultLocationID = loc.ID
|
||||
|
||||
template, 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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
// Prepare the data with proper format for API
|
||||
const payload = {
|
||||
...updateData,
|
||||
defaultLocationId: updateData.defaultLocation?.id ?? "",
|
||||
defaultLocationId: updateData.defaultLocation?.id ?? null,
|
||||
};
|
||||
|
||||
const { error, data } = await api.templates.update(templateId.value, payload);
|
||||
|
||||
Reference in New Issue
Block a user