refactor(backend): migrate from sql.ErrNoRows to pgx.ErrNoRows

Replace all database/sql.ErrNoRows checks with pgx.ErrNoRows across backend handlers.

Migration includes: jwt.go, local.go, admin_reserve.go, custom_services.go,
discount_campaigns.go, services.go, account.go, customer_relationship.go,
guest.go. Also removes unused test_helpers.go resetTestData function.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-06-20 16:58:08 +01:00
co-authored by Sisyphus
parent b03c4f6247
commit efd3ad5405
10 changed files with 24 additions and 26 deletions
+3 -1
View File
@@ -3,6 +3,7 @@ package user
import (
"context"
"database/sql"
"errors"
"fmt"
"log"
"net/http"
@@ -13,6 +14,7 @@ import (
"crussell/internal/dav"
"crussell/internal/s3"
"crussell/mw"
"github.com/jackc/pgx/v5"
)
// DELETE /api/user/account
@@ -28,7 +30,7 @@ func DeleteAccountHandler(w http.ResponseWriter, r *http.Request) {
err := db.DB.QueryRow(r.Context(), `SELECT account_role, profile_pic_url FROM users WHERE id = $1`, userID).
Scan(&accountRole, &profilePicURL)
if err != nil {
if err == sql.ErrNoRows {
if errors.Is(err, pgx.ErrNoRows) {
http.Error(w, "user not found", http.StatusNotFound)
return
}
@@ -13,6 +13,7 @@ import (
"github.com/go-chi/chi/v5"
"crussell/db"
"github.com/jackc/pgx/v5"
"crussell/internal/validators"
)
@@ -68,7 +69,7 @@ func GetCustomerRelationshipHandler(w http.ResponseWriter, r *http.Request) {
LEFT JOIN payments p ON p.booking_id = b.id
WHERE b.user_id = $1
`, userID).Scan(&result.TotalSpend, &result.TotalSaved, &result.TotalTips, &result.TotalVisits, &firstVisit, &lastVisit)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
log.Printf("Failed to get customer relationship data for user %s: %v", userID, err)
}
@@ -113,7 +114,7 @@ func GetCustomerRelationshipHandler(w http.ResponseWriter, r *http.Request) {
ORDER BY count DESC
LIMIT 5
`, userID)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
if err != nil && !errors.Is(err, pgx.ErrNoRows) {
log.Printf("Failed to get top services for user %s: %v", userID, err)
} else {
defer rows.Close()
+2 -2
View File
@@ -1,7 +1,6 @@
package user
import (
"database/sql"
"encoding/json"
"errors"
"log"
@@ -12,6 +11,7 @@ import (
"crussell/db"
"crussell/handlers/auth"
"crussell/internal/validators"
"github.com/jackc/pgx/v5"
)
type CreateGuestUserRequest struct {
@@ -172,7 +172,7 @@ func CheckEmailHandler(w http.ResponseWriter, r *http.Request) {
s := "check"
suggestion = &s
}
} else if !errors.Is(err, sql.ErrNoRows) {
} else if !errors.Is(err, pgx.ErrNoRows) {
log.Printf("Failed to check email: %v", err)
http.Error(w, "database error", http.StatusInternalServerError)
return