fix(loyalty): resolve critical production readiness issues
Some checks failed
Some checks failed
- Add pessimistic locking (SELECT FOR UPDATE) on card write operations to prevent race conditions in stamp_service and points_service - Replace 16 console.log/error/warn calls with LogConfig.createLogger() in 3 storefront JS files (dashboard, history, enroll) - Delete all stale lu.json locale files across 8 modules (lb is the correct ISO 639-1 code for Luxembourgish) - Update architecture rules and docs to reference lb.json not lu.json - Add production-readiness.md report for loyalty module Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -125,6 +125,9 @@ class StampService:
|
||||
if stamps_today >= program.max_daily_stamps:
|
||||
raise DailyStampLimitException(program.max_daily_stamps, stamps_today)
|
||||
|
||||
# Re-fetch with row lock to prevent concurrent modification
|
||||
card = card_service.get_card_for_update(db, card.id)
|
||||
|
||||
# Add the stamp
|
||||
card.stamp_count += 1
|
||||
card.total_stamps_earned += 1
|
||||
@@ -249,6 +252,9 @@ class StampService:
|
||||
raise StaffPinRequiredException()
|
||||
verified_pin = pin_service.verify_pin(db, program.id, staff_pin, store_id=store_id)
|
||||
|
||||
# Re-fetch with row lock to prevent concurrent modification
|
||||
card = card_service.get_card_for_update(db, card.id)
|
||||
|
||||
# Redeem stamps
|
||||
now = datetime.now(UTC)
|
||||
stamps_redeemed = program.stamps_target
|
||||
@@ -383,6 +389,9 @@ class StampService:
|
||||
"stamp_count": card.stamp_count,
|
||||
}
|
||||
|
||||
# Re-fetch with row lock to prevent concurrent modification
|
||||
card = card_service.get_card_for_update(db, card.id)
|
||||
|
||||
# Void the stamps (can reduce balance below what was earned)
|
||||
now = datetime.now(UTC)
|
||||
actual_voided = min(stamps_to_void, card.stamp_count)
|
||||
|
||||
Reference in New Issue
Block a user