fix: add error logging to remaining nolint:errcheck scan sites for observability
CI / Env docs check (push) Successful in 15s
CI / Docker compose check (push) Successful in 16s
CI / Nginx config check (push) Successful in 20s
CI / Frontend major deps (push) Successful in 30s
CI / Frontend deps check (push) Successful in 32s
CI / Secrets scan (push) Successful in 47s
CI / Go build (push) Successful in 44s
CI / Frontend build (push) Successful in 49s
CI / Go vet (dev) (push) Has been cancelled
CI / Go vet (prod) (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / Staticcheck (dev) (push) Has been cancelled
CI / Staticcheck (prod) (push) Has been cancelled
CI / Security scan (dev) (push) Has been cancelled
CI / Security scan (prod) (push) Has been cancelled
CI / go mod tidy (push) Has been cancelled
CI / Tests (prod) (push) Has been cancelled
CI / Tests (dev) (push) Has been cancelled
CI / Race (prod) (push) Has been cancelled
CI / Race (dev) (push) Has been cancelled
CI / Go vulnerabilities (push) Has been cancelled
CI / Knip (push) Has been cancelled
CI / Frontend a11y check (push) Has been cancelled
CI / Svelte strict check (push) Has been cancelled
CI / Frontend QC (audit) (push) Has been cancelled
CI / Frontend QC (typecheck) (push) Has been cancelled
CI / Frontend QC (lint) (push) Has been cancelled
CI / Env docs check (push) Successful in 15s
CI / Docker compose check (push) Successful in 16s
CI / Nginx config check (push) Successful in 20s
CI / Frontend major deps (push) Successful in 30s
CI / Frontend deps check (push) Successful in 32s
CI / Secrets scan (push) Successful in 47s
CI / Go build (push) Successful in 44s
CI / Frontend build (push) Successful in 49s
CI / Go vet (dev) (push) Has been cancelled
CI / Go vet (prod) (push) Has been cancelled
CI / golangci-lint (push) Has been cancelled
CI / Staticcheck (dev) (push) Has been cancelled
CI / Staticcheck (prod) (push) Has been cancelled
CI / Security scan (dev) (push) Has been cancelled
CI / Security scan (prod) (push) Has been cancelled
CI / go mod tidy (push) Has been cancelled
CI / Tests (prod) (push) Has been cancelled
CI / Tests (dev) (push) Has been cancelled
CI / Race (prod) (push) Has been cancelled
CI / Race (dev) (push) Has been cancelled
CI / Go vulnerabilities (push) Has been cancelled
CI / Knip (push) Has been cancelled
CI / Frontend a11y check (push) Has been cancelled
CI / Svelte strict check (push) Has been cancelled
CI / Frontend QC (audit) (push) Has been cancelled
CI / Frontend QC (typecheck) (push) Has been cancelled
CI / Frontend QC (lint) (push) Has been cancelled
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"log"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -167,13 +168,15 @@ func GetCustomServices(w http.ResponseWriter, r *http.Request) {
|
|||||||
// so pgx does not return "conn busy" on the same transaction.
|
// so pgx does not return "conn busy" on the same transaction.
|
||||||
if q != "" {
|
if q != "" {
|
||||||
var countTotal int64
|
var countTotal int64
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services WHERE name ILIKE $1 OR description ILIKE $1", "%"+q+"%").Scan(&countTotal); err != nil {
|
||||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services WHERE name ILIKE $1 OR description ILIKE $1", "%"+q+"%").Scan(&countTotal)
|
log.Printf("Failed to scan filtered custom services count: %v", err)
|
||||||
|
}
|
||||||
total = countTotal
|
total = countTotal
|
||||||
} else {
|
} else {
|
||||||
var countTotal int64
|
var countTotal int64
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services").Scan(&countTotal); err != nil {
|
||||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM custom_services").Scan(&countTotal)
|
log.Printf("Failed to scan custom services count: %v", err)
|
||||||
|
}
|
||||||
total = countTotal
|
total = countTotal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2776,8 +2776,9 @@ func ProgressBookingHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if bookingTotal > 0 {
|
if bookingTotal > 0 {
|
||||||
var userBookingCount int
|
var userBookingCount int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := tx.QueryRow(r.Context(), `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, booking.User.ID).Scan(&userBookingCount); err != nil {
|
||||||
_ = tx.QueryRow(r.Context(), `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, booking.User.ID).Scan(&userBookingCount)
|
log.Printf("Failed to scan user completed booking count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
var milestoneCampaignID string
|
var milestoneCampaignID string
|
||||||
var milestonePercent float64
|
var milestonePercent float64
|
||||||
@@ -2817,8 +2818,9 @@ func ProgressBookingHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
if !globalMilestoneApplied {
|
if !globalMilestoneApplied {
|
||||||
var globalCount int
|
var globalCount int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := tx.QueryRow(r.Context(), `SELECT COUNT(*) FROM bookings WHERE status = 'completed'`).Scan(&globalCount); err != nil {
|
||||||
_ = tx.QueryRow(r.Context(), `SELECT COUNT(*) FROM bookings WHERE status = 'completed'`).Scan(&globalCount)
|
log.Printf("Failed to scan global completed booking count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
var hasInPersonPayment bool
|
var hasInPersonPayment bool
|
||||||
if err := tx.QueryRow(r.Context(), `
|
if err := tx.QueryRow(r.Context(), `
|
||||||
@@ -2863,8 +2865,9 @@ func ProgressBookingHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var firstVisitDate time.Time
|
var firstVisitDate time.Time
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := tx.QueryRow(r.Context(), `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, booking.User.ID).Scan(&firstVisitDate); err != nil {
|
||||||
_ = tx.QueryRow(r.Context(), `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, booking.User.ID).Scan(&firstVisitDate)
|
log.Printf("Failed to scan first visit date: %v", err)
|
||||||
|
}
|
||||||
if !firstVisitDate.IsZero() {
|
if !firstVisitDate.IsZero() {
|
||||||
annRows, err := tx.Query(r.Context(), `
|
annRows, err := tx.Query(r.Context(), `
|
||||||
SELECT id, discount_percent, milestone_value, milestone_unit FROM discount_campaigns
|
SELECT id, discount_percent, milestone_value, milestone_unit FROM discount_campaigns
|
||||||
|
|||||||
@@ -1685,8 +1685,9 @@ func AdminListEditRequestsHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
var total int
|
var total int
|
||||||
|
|
||||||
// Count query (no ORDER BY needed).
|
// Count query (no ORDER BY needed).
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM booking_edit_requests").Scan(&total); err != nil {
|
||||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM booking_edit_requests").Scan(&total)
|
log.Printf("Failed to scan booking edit request count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
rows, err := db.Conn.Query(r.Context(), baseQuery, args...)
|
rows, err := db.Conn.Query(r.Context(), baseQuery, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -126,8 +126,9 @@ func GetNotifications(w http.ResponseWriter, r *http.Request) {
|
|||||||
if !includeAcknowledged {
|
if !includeAcknowledged {
|
||||||
countWhere += " WHERE an.acknowledged_at IS NULL"
|
countWhere += " WHERE an.acknowledged_at IS NULL"
|
||||||
}
|
}
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM admin_notifications an"+countWhere).Scan(&total); err != nil {
|
||||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM admin_notifications an"+countWhere).Scan(&total)
|
log.Printf("Failed to scan notification count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
// Query
|
// Query
|
||||||
rows, err := db.Conn.Query(r.Context(), baseQuery, args...)
|
rows, err := db.Conn.Query(r.Context(), baseQuery, args...)
|
||||||
|
|||||||
@@ -207,11 +207,13 @@ func GetGiftCards(w http.ResponseWriter, r *http.Request) {
|
|||||||
if searchTerm != "" {
|
if searchTerm != "" {
|
||||||
countArgs = append(countArgs, "%"+searchTerm+"%")
|
countArgs = append(countArgs, "%"+searchTerm+"%")
|
||||||
}
|
}
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards "+whereSQL, countArgs...).Scan(&gcTotal); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards "+whereSQL, countArgs...).Scan(&gcTotal)
|
log.Printf("Failed to scan filtered gift card count: %v", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards").Scan(&gcTotal); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM gift_cards").Scan(&gcTotal)
|
log.Printf("Failed to scan gift card count: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gcRows, err := db.Conn.Query(ctx, gcListQuery, gcListArgs...)
|
gcRows, err := db.Conn.Query(ctx, gcListQuery, gcListArgs...)
|
||||||
@@ -283,13 +285,15 @@ func GetGiftCards(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// Count query for user balances.
|
// Count query for user balances.
|
||||||
if searchTerm != "" {
|
if searchTerm != "" {
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM user_giftcard_balances b
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM user_giftcard_balances b
|
|
||||||
JOIN users u ON b.user_id = u.id
|
JOIN users u ON b.user_id = u.id
|
||||||
WHERE u.n_first_name ILIKE $1 OR u.n_last_name ILIKE $1 OR u.email ILIKE $1`, "%"+searchTerm+"%").Scan(&ubTotal)
|
WHERE u.n_first_name ILIKE $1 OR u.n_last_name ILIKE $1 OR u.email ILIKE $1`, "%"+searchTerm+"%").Scan(&ubTotal); err != nil {
|
||||||
|
log.Printf("Failed to scan filtered user balance count: %v", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM user_giftcard_balances").Scan(&ubTotal); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, "SELECT COUNT(*) FROM user_giftcard_balances").Scan(&ubTotal)
|
log.Printf("Failed to scan user balance count: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ubRows.Next() {
|
for ubRows.Next() {
|
||||||
|
|||||||
@@ -165,8 +165,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
|
|||||||
ORDER BY discount_percent DESC LIMIT 1
|
ORDER BY discount_percent DESC LIMIT 1
|
||||||
`).Scan(&campaignID, &campaignPercent, &campaignName); err == nil && campaignID != "" {
|
`).Scan(&campaignID, &campaignPercent, &campaignName); err == nil && campaignID != "" {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists)
|
log.Printf("Failed to scan campaign discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
amount := roundTo2(bookingTotal * campaignPercent / 100)
|
amount := roundTo2(bookingTotal * campaignPercent / 100)
|
||||||
resp.Discounts = append(resp.Discounts, DiscountPreview{
|
resp.Discounts = append(resp.Discounts, DiscountPreview{
|
||||||
@@ -180,8 +181,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
var userBookingCount int
|
var userBookingCount int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount)
|
log.Printf("Failed to scan user completed booking count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
var milestoneCampaignID string
|
var milestoneCampaignID string
|
||||||
var milestonePercent float64
|
var milestonePercent float64
|
||||||
@@ -197,8 +199,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
|
|||||||
|
|
||||||
if milestoneCampaignID != "" {
|
if milestoneCampaignID != "" {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists)
|
log.Printf("Failed to scan milestone discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
amount := roundTo2(bookingTotal * milestonePercent / 100)
|
amount := roundTo2(bookingTotal * milestonePercent / 100)
|
||||||
resp.Discounts = append(resp.Discounts, DiscountPreview{
|
resp.Discounts = append(resp.Discounts, DiscountPreview{
|
||||||
@@ -212,8 +215,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
var firstVisitDate time.Time
|
var firstVisitDate time.Time
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate)
|
log.Printf("Failed to scan first visit date: %v", err)
|
||||||
|
}
|
||||||
if !firstVisitDate.IsZero() {
|
if !firstVisitDate.IsZero() {
|
||||||
type annCamp struct {
|
type annCamp struct {
|
||||||
id string
|
id string
|
||||||
@@ -239,8 +243,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
|
|||||||
|
|
||||||
for _, c := range campaigns {
|
for _, c := range campaigns {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists)
|
log.Printf("Failed to scan anniversary discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists > 0 {
|
if exists > 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -276,8 +281,9 @@ func calculateDiscountPreview(ctx context.Context, bookingID string, userID stri
|
|||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, userID).Scan(&rdID, &rdPercent); err == nil && rdID != "" {
|
`, userID).Scan(&rdID, &rdPercent); err == nil && rdID != "" {
|
||||||
exists := 0
|
exists := 0
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists); err != nil {
|
||||||
_ = db.Conn.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists)
|
log.Printf("Failed to scan referral discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
amount := roundTo2(bookingTotal * rdPercent / 100)
|
amount := roundTo2(bookingTotal * rdPercent / 100)
|
||||||
resp.Discounts = append(resp.Discounts, DiscountPreview{
|
resp.Discounts = append(resp.Discounts, DiscountPreview{
|
||||||
@@ -1080,11 +1086,12 @@ func CreateBookingPayment(w http.ResponseWriter, r *http.Request) {
|
|||||||
// would create a credit balance or require a refund.
|
// would create a credit balance or require a refund.
|
||||||
func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingID string, userID string) {
|
func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingID string, userID string) {
|
||||||
var existingPayment int
|
var existingPayment int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `
|
||||||
_ = q.QueryRow(ctx, `
|
|
||||||
SELECT COUNT(*) FROM payments
|
SELECT COUNT(*) FROM payments
|
||||||
WHERE booking_id = $1 AND status = 'completed' AND payment_method NOT IN ('discount', 'on_the_house')
|
WHERE booking_id = $1 AND status = 'completed' AND payment_method NOT IN ('discount', 'on_the_house')
|
||||||
`, bookingID).Scan(&existingPayment)
|
`, bookingID).Scan(&existingPayment); err != nil {
|
||||||
|
log.Printf("Failed to scan existing payment count: %v", err)
|
||||||
|
}
|
||||||
// Only block if this is the 2nd+ real payment — the first payment should still
|
// Only block if this is the 2nd+ real payment — the first payment should still
|
||||||
// trigger discount application (existingPayment counts already-completed payments
|
// trigger discount application (existingPayment counts already-completed payments
|
||||||
// visible within the transaction, including the just-inserted one).
|
// visible within the transaction, including the just-inserted one).
|
||||||
@@ -1113,8 +1120,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
ORDER BY discount_percent DESC LIMIT 1
|
ORDER BY discount_percent DESC LIMIT 1
|
||||||
`).Scan(&campaignID, &campaignPercent); err == nil && campaignID != "" {
|
`).Scan(&campaignID, &campaignPercent); err == nil && campaignID != "" {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, campaignID).Scan(&exists)
|
log.Printf("Failed to scan time-based campaign discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
discountAmount := roundTo2(bookingTotal * campaignPercent / 100)
|
discountAmount := roundTo2(bookingTotal * campaignPercent / 100)
|
||||||
if _, err := q.Exec(ctx, `
|
if _, err := q.Exec(ctx, `
|
||||||
@@ -1139,8 +1147,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
}
|
}
|
||||||
|
|
||||||
var userBookingCount int
|
var userBookingCount int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&userBookingCount)
|
log.Printf("Failed to scan user booking count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
var milestoneCampaignID string
|
var milestoneCampaignID string
|
||||||
var milestonePercent float64
|
var milestonePercent float64
|
||||||
@@ -1155,8 +1164,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
|
|
||||||
if milestoneCampaignID != "" {
|
if milestoneCampaignID != "" {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, milestoneCampaignID).Scan(&exists)
|
log.Printf("Failed to scan milestone campaign discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
discountAmount := roundTo2(bookingTotal * milestonePercent / 100)
|
discountAmount := roundTo2(bookingTotal * milestonePercent / 100)
|
||||||
if _, err := q.Exec(ctx, `
|
if _, err := q.Exec(ctx, `
|
||||||
@@ -1181,8 +1191,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
}
|
}
|
||||||
|
|
||||||
var firstVisitDate time.Time
|
var firstVisitDate time.Time
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT MIN(start_time) FROM bookings WHERE user_id = $1 AND status = 'completed'`, userID).Scan(&firstVisitDate)
|
log.Printf("Failed to scan first visit date: %v", err)
|
||||||
|
}
|
||||||
if !firstVisitDate.IsZero() {
|
if !firstVisitDate.IsZero() {
|
||||||
annRows, err := q.Query(ctx, `
|
annRows, err := q.Query(ctx, `
|
||||||
SELECT id, discount_percent, milestone_value, milestone_unit FROM discount_campaigns
|
SELECT id, discount_percent, milestone_value, milestone_unit FROM discount_campaigns
|
||||||
@@ -1207,8 +1218,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
|
|
||||||
for _, c := range campaigns {
|
for _, c := range campaigns {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, c.id).Scan(&exists)
|
log.Printf("Failed to scan anniversary discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists > 0 {
|
if exists > 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -1256,8 +1268,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
SELECT payment_method FROM payments WHERE booking_id = $1 AND payment_method NOT IN ('discount', 'on_the_house') ORDER BY created_at ASC LIMIT 1
|
SELECT payment_method FROM payments WHERE booking_id = $1 AND payment_method NOT IN ('discount', 'on_the_house') ORDER BY created_at ASC LIMIT 1
|
||||||
`, bookingID).Scan(&firstPaymentMethod); err == nil && firstPaymentMethod == "in_person_card" {
|
`, bookingID).Scan(&firstPaymentMethod); err == nil && firstPaymentMethod == "in_person_card" {
|
||||||
var globalCount int
|
var globalCount int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE status = 'completed'`).Scan(&globalCount); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT COUNT(*) FROM bookings WHERE status = 'completed'`).Scan(&globalCount)
|
log.Printf("Failed to scan global completed booking count: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
var globalCampaignID string
|
var globalCampaignID string
|
||||||
var globalPercent float64
|
var globalPercent float64
|
||||||
@@ -1274,8 +1287,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
|
|
||||||
if globalCampaignID != "" {
|
if globalCampaignID != "" {
|
||||||
var exists int
|
var exists int
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, globalCampaignID).Scan(&exists); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND source_id = $2`, bookingID, globalCampaignID).Scan(&exists)
|
log.Printf("Failed to scan global campaign discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
discountAmount := roundTo2(bookingTotal * globalPercent / 100)
|
discountAmount := roundTo2(bookingTotal * globalPercent / 100)
|
||||||
if _, err := q.Exec(ctx, `
|
if _, err := q.Exec(ctx, `
|
||||||
@@ -1310,8 +1324,9 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
|||||||
LIMIT 1
|
LIMIT 1
|
||||||
`, userID).Scan(&rdID, &rdPercent); err == nil && rdID != "" {
|
`, userID).Scan(&rdID, &rdPercent); err == nil && rdID != "" {
|
||||||
exists := 0
|
exists := 0
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists); err != nil {
|
||||||
_ = q.QueryRow(ctx, `SELECT 1 FROM booking_discounts WHERE booking_id = $1 AND discount_source = 'referral' AND source_id = $2`, bookingID, rdID).Scan(&exists)
|
log.Printf("Failed to scan referral discount existence: %v", err)
|
||||||
|
}
|
||||||
if exists == 0 {
|
if exists == 0 {
|
||||||
discountAmount := roundTo2(bookingTotal * rdPercent / 100)
|
discountAmount := roundTo2(bookingTotal * rdPercent / 100)
|
||||||
if _, err := q.Exec(ctx, `
|
if _, err := q.Exec(ctx, `
|
||||||
|
|||||||
@@ -565,13 +565,15 @@ func ListAdminUsersHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
// Run BEFORE the data query to avoid "conn busy" errors when routing
|
// Run BEFORE the data query to avoid "conn busy" errors when routing
|
||||||
// through a per-test transaction (pgx.Tx does not support concurrent queries).
|
// through a per-test transaction (pgx.Tx does not support concurrent queries).
|
||||||
if searchTerm != "" {
|
if searchTerm != "" {
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(r.Context(), `SELECT COUNT(DISTINCT u.id) FROM users u
|
||||||
_ = db.Conn.QueryRow(r.Context(), `SELECT COUNT(DISTINCT u.id) FROM users u
|
|
||||||
LEFT JOIN bookings b ON u.id = b.user_id
|
LEFT JOIN bookings b ON u.id = b.user_id
|
||||||
WHERE u.fn ILIKE $1 OR u.email ILIKE $1 OR u.phone ILIKE $1`, "%"+searchTerm+"%").Scan(&total)
|
WHERE u.fn ILIKE $1 OR u.email ILIKE $1 OR u.phone ILIKE $1`, "%"+searchTerm+"%").Scan(&total); err != nil {
|
||||||
|
log.Printf("Failed to scan filtered user count: %v", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//nolint:errcheck // zero value is acceptable fallback on scan failure
|
if err := db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM users").Scan(&total); err != nil {
|
||||||
_ = db.Conn.QueryRow(r.Context(), "SELECT COUNT(*) FROM users").Scan(&total)
|
log.Printf("Failed to scan user count: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get users list
|
// Get users list
|
||||||
|
|||||||
Reference in New Issue
Block a user