A continuation of HomeBox the inventory and organization system built for the Home User
Improve filter for maintenances (#367)
Nikolai K2d2e3fe891cf
diff --git a/backend/internal/data/repo/repo_maintenance_entry.go b/backend/internal/data/repo/repo_maintenance_entry.goindex 6f5c135b..b3e98349 100644--- a/backend/internal/data/repo/repo_maintenance_entry.go+++ b/backend/internal/data/repo/repo_maintenance_entry.go@@ -134,13 +134,15 @@ func (r *MaintenanceEntryRepository) GetMaintenanceByItemID(ctx context.Context,query = query.Where(maintenanceentry.Or(maintenanceentry.DateIsNil(),maintenanceentry.DateEQ(time.Time{}),+ maintenanceentry.DateGT(time.Now()),))} else if filters.Status == MaintenanceFilterStatusCompleted {query = query.Where(maintenanceentry.Not(maintenanceentry.Or(maintenanceentry.DateIsNil(),- maintenanceentry.DateEQ(time.Time{})),- ))+ maintenanceentry.DateEQ(time.Time{}),+ maintenanceentry.DateGT(time.Now()),+ )))}entries, err := query.WithItem().Order(maintenanceentry.ByScheduledDate()).All(ctx)diff --git a/backend/internal/data/repo/repo_maintenance_entry_test.go b/backend/internal/data/repo/repo_maintenance_entry_test.goindex 6f6bc0fd..d9e96078 100644--- a/backend/internal/data/repo/repo_maintenance_entry_test.go+++ b/backend/internal/data/repo/repo_maintenance_entry_test.go@@ -32,8 +32,8 @@ func getPrevMonth(now time.Time) time.Time {func TestMaintenanceEntryRepository_GetLog(t *testing.T) {item := useItems(t, 1)[0]- // Create 10 maintenance entries for the item- created := make([]MaintenanceEntryCreate, 10)+ // Create 11 maintenance entries for the item+ created := make([]MaintenanceEntryCreate, 11)thisMonth := time.Now()lastMonth := getPrevMonth(thisMonth)@@ -52,6 +52,14 @@ func TestMaintenanceEntryRepository_GetLog(t *testing.T) {}}+ // Add an entry completed in the future+ created[10] = MaintenanceEntryCreate{+ CompletedDate: types.DateFromTime(time.Now().AddDate(0, 0, 1)),+ Name: "Maintenance",+ Description: "Maintenance description",+ Cost: 10,+ }+for _, entry := range created {_, err := tRepos.MaintEntry.Create(context.Background(), item.ID, entry)if err != nil {