From 1564f93d25e8fdbd18e4ff5250a8104f471c3fcb Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sun, 21 Jun 2026 21:47:31 +0100 Subject: [PATCH] fix(user): fix column aliases and replace SELECT * with explicit columns Fix customer_relationship.go: use consistent 'cnt' alias instead of duplicate 'count' column. Fix profile.go: replace SELECT * with explicit column list to avoid new computed booking columns breaking the admin listing query. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- backend/handlers/user/customer_relationship.go | 6 +++--- backend/handlers/user/profile.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/handlers/user/customer_relationship.go b/backend/handlers/user/customer_relationship.go index c890af3..0fd3a14 100644 --- a/backend/handlers/user/customer_relationship.go +++ b/backend/handlers/user/customer_relationship.go @@ -97,21 +97,21 @@ func GetCustomerRelationshipHandler(w http.ResponseWriter, r *http.Request) { rows, err := db.Conn.Query(r.Context(), ` SELECT name, cnt FROM ( - SELECT s.name, COUNT(*) as count, COUNT(*) as cnt + SELECT s.name, COUNT(*) as cnt FROM booking_services bsvc JOIN bookings b ON bsvc.booking_id = b.id JOIN services s ON bsvc.service_id = s.id WHERE b.user_id = $1 AND b.status = 'completed' GROUP BY s.name UNION ALL - SELECT cs.name, COUNT(*) as count, COUNT(*) as cnt + SELECT cs.name, COUNT(*) as cnt FROM booking_custom_services bcs JOIN bookings b ON bcs.booking_id = b.id JOIN custom_services cs ON bcs.custom_service_id = cs.id WHERE b.user_id = $1 AND b.status = 'completed' GROUP BY cs.name ) combined - ORDER BY count DESC + ORDER BY cnt DESC LIMIT 5 `, userID) if err != nil && !errors.Is(err, pgx.ErrNoRows) { diff --git a/backend/handlers/user/profile.go b/backend/handlers/user/profile.go index 4f3397e..4d6e16a 100644 --- a/backend/handlers/user/profile.go +++ b/backend/handlers/user/profile.go @@ -512,7 +512,7 @@ func ListAdminUsersHandler(w http.ResponseWriter, r *http.Request) { if searchTerm != "" { searchPattern := "%" + searchTerm + "%" - innerWithWhere := `SELECT * FROM (` + innerQuery + ` + innerWithWhere := `SELECT id, fn, email, phone, account_role, created_at, previous_first_name, previous_last_name, completed_count FROM (` + innerQuery + ` WHERE (u.fn ILIKE $1 OR u.email ILIKE $1 OR u.phone ILIKE $1) ) sub` @@ -532,7 +532,7 @@ func ListAdminUsersHandler(w http.ResponseWriter, r *http.Request) { listQuery += ` ORDER BY completed_count DESC, created_at DESC, id DESC LIMIT $` + strconv.Itoa(len(listArgs)+1) listArgs = append(listArgs, perPage+1) } else { - innerNoWhere := `SELECT * FROM (` + innerQuery + `) sub` + innerNoWhere := `SELECT id, fn, email, phone, account_role, created_at, previous_first_name, previous_last_name, completed_count FROM (` + innerQuery + `) sub` if cursorStr != "" { cursorCount, cursorCreatedAt, cursorID, err := validators.ParseCursor3(cursorStr)