fix: wrong sql query for drive listing

This commit is contained in:
2026-01-01 18:35:59 +00:00
parent 88492dd876
commit 12ed13b2d6
2 changed files with 15 additions and 2 deletions

View File

@@ -103,6 +103,19 @@ func TestRegistrationFlow(t *testing.T) {
t.Fatalf("expected account.id and drive.id to be set")
}
t.Run("drives list", func(t *testing.T) {
var drives []struct {
ID string `json:"id"`
}
doJSON(t, s.app, http.MethodGet, "/api/drives", reg.AccessToken, nil, http.StatusOK, &drives)
if len(drives) != 1 {
t.Fatalf("expected 1 drive, got %d", len(drives))
}
if drives[0].ID != reg.Drive.ID {
t.Fatalf("unexpected drive id: got %q want %q", drives[0].ID, reg.Drive.ID)
}
})
t.Run("users/me", func(t *testing.T) {
var me struct {
ID string `json:"id"`

View File

@@ -87,10 +87,10 @@ func (s *Service) ListAccessibleDrives(ctx context.Context, db bun.IDB, orgID uu
func (s *Service) ListDrivesForUser(ctx context.Context, db bun.IDB, userID uuid.UUID) ([]*Drive, error) {
var drives []*Drive
err := db.NewSelect().Model(&drives).
Join("JOIN accounts a ON a.org_id = drives.org_id").
Join("JOIN accounts a ON a.org_id = drive.org_id").
Where("a.user_id = ?", userID).
Where("a.status = ?", account.StatusActive).
Where("drives.owner_account_id IS NULL OR drives.owner_account_id = a.id").
Where("drive.owner_account_id IS NULL OR drive.owner_account_id = a.id").
Scan(ctx)
if err != nil {
if errors.Is(err, sql.ErrNoRows) {