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 <clio-agent@sisyphuslabs.ai>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user