mirror of
https://github.com/get-drexa/drive.git
synced 2026-02-02 06:01:17 +00:00
fix: wrong sql query for drive listing
This commit is contained in:
@@ -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"`
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user