fix: add error logging to discount campaign payment/times_redeemed execs
This commit is contained in:
@@ -1123,15 +1123,17 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
||||
`, bookingID, userID, campaignID, campaignPercent, bookingTotal, discountAmount); err != nil {
|
||||
log.Printf("Failed to insert time-based campaign discount: %v", err)
|
||||
} else {
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
if _, err := q.Exec(ctx, `
|
||||
INSERT INTO payments (booking_id, payment_type, payment_method, amount, status, created_by)
|
||||
VALUES ($1, 'partial', 'discount', $2, 'completed', $3)
|
||||
`, bookingID, discountAmount, userID)
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
`, bookingID, discountAmount, userID); err != nil {
|
||||
log.Printf("ALERT: failed to insert discount payment record for campaign %s, booking %s: %v", campaignID, bookingID, err)
|
||||
}
|
||||
if _, err := q.Exec(ctx, `
|
||||
UPDATE discount_campaigns SET times_redeemed = times_redeemed + 1 WHERE id = $1
|
||||
`, campaignID)
|
||||
`, campaignID); err != nil {
|
||||
log.Printf("ALERT: failed to increment times_redeemed for campaign %s, booking %s: %v", campaignID, bookingID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1163,15 +1165,17 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
||||
`, bookingID, userID, milestoneCampaignID, milestonePercent, bookingTotal, discountAmount); err != nil {
|
||||
log.Printf("Failed to insert per-user milestone discount: %v", err)
|
||||
} else {
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
if _, err := q.Exec(ctx, `
|
||||
INSERT INTO payments (booking_id, payment_type, payment_method, amount, status, created_by)
|
||||
VALUES ($1, 'partial', 'discount', $2, 'completed', $3)
|
||||
`, bookingID, discountAmount, userID)
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
`, bookingID, discountAmount, userID); err != nil {
|
||||
log.Printf("ALERT: failed to insert discount payment record for campaign %s, booking %s: %v", milestoneCampaignID, bookingID, err)
|
||||
}
|
||||
if _, err := q.Exec(ctx, `
|
||||
UPDATE discount_campaigns SET times_redeemed = times_redeemed + 1 WHERE id = $1
|
||||
`, milestoneCampaignID)
|
||||
`, milestoneCampaignID); err != nil {
|
||||
log.Printf("ALERT: failed to increment times_redeemed for campaign %s, booking %s: %v", milestoneCampaignID, bookingID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1227,15 +1231,17 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
||||
`, bookingID, userID, c.id, c.pct, bookingTotal, discountAmount); err != nil {
|
||||
log.Printf("Failed to insert anniversary discount: %v", err)
|
||||
} else {
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
if _, err := q.Exec(ctx, `
|
||||
INSERT INTO payments (booking_id, payment_type, payment_method, amount, status, created_by)
|
||||
VALUES ($1, 'partial', 'discount', $2, 'completed', $3)
|
||||
`, bookingID, discountAmount, userID)
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
`, bookingID, discountAmount, userID); err != nil {
|
||||
log.Printf("ALERT: failed to insert discount payment record for campaign %s, booking %s: %v", c.id, bookingID, err)
|
||||
}
|
||||
if _, err := q.Exec(ctx, `
|
||||
UPDATE discount_campaigns SET times_redeemed = times_redeemed + 1 WHERE id = $1
|
||||
`, c.id)
|
||||
`, c.id); err != nil {
|
||||
log.Printf("ALERT: failed to increment times_redeemed for campaign %s, booking %s: %v", c.id, bookingID, err)
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -1278,15 +1284,17 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
||||
`, bookingID, userID, globalCampaignID, globalPercent, bookingTotal, discountAmount); err != nil {
|
||||
log.Printf("Failed to insert global milestone discount: %v", err)
|
||||
} else {
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
if _, err := q.Exec(ctx, `
|
||||
INSERT INTO payments (booking_id, payment_type, payment_method, amount, status, created_by)
|
||||
VALUES ($1, 'partial', 'discount', $2, 'completed', $3)
|
||||
`, bookingID, discountAmount, userID)
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
`, bookingID, discountAmount, userID); err != nil {
|
||||
log.Printf("ALERT: failed to insert discount payment record for campaign %s, booking %s: %v", globalCampaignID, bookingID, err)
|
||||
}
|
||||
if _, err := q.Exec(ctx, `
|
||||
UPDATE discount_campaigns SET times_redeemed = times_redeemed + 1 WHERE id = $1
|
||||
`, globalCampaignID)
|
||||
`, globalCampaignID); err != nil {
|
||||
log.Printf("ALERT: failed to increment times_redeemed for campaign %s, booking %s: %v", globalCampaignID, bookingID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1310,15 +1318,17 @@ func applyEligibleCampaignsAtPayment(ctx context.Context, q db.Querier, bookingI
|
||||
INSERT INTO booking_discounts (booking_id, user_id, discount_source, source_id, campaign_type, milestone_type, discount_percent, original_total, discount_amount)
|
||||
VALUES ($1, $2, 'referral', $3, NULL, NULL, $4, $5, $6)
|
||||
`, bookingID, userID, rdID, rdPercent, bookingTotal, discountAmount); err == nil {
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
if _, err := q.Exec(ctx, `
|
||||
INSERT INTO payments (booking_id, payment_type, payment_method, amount, status, created_by)
|
||||
VALUES ($1, 'partial', 'discount', $2, 'completed', $3)
|
||||
`, bookingID, discountAmount, userID)
|
||||
//nolint:errcheck // exec errors are non-critical; best-effort inserts/updates
|
||||
_, _ = q.Exec(ctx, `
|
||||
`, bookingID, discountAmount, userID); err != nil {
|
||||
log.Printf("ALERT: failed to insert discount payment record for campaign %s, booking %s: %v", rdID, bookingID, err)
|
||||
}
|
||||
if _, err := q.Exec(ctx, `
|
||||
UPDATE referral_discounts SET used = TRUE, used_at = NOW() WHERE id = $1
|
||||
`, rdID)
|
||||
`, rdID); err != nil {
|
||||
log.Printf("ALERT: failed to mark referral discount as used, booking %s: %v", bookingID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user