Type: BUG
Severity: High
Component: backend/src/routes/bets.js
Context
The POST /api/bets route validates the market with: SELECT * FROM markets WHERE id = AND resolved = FALSE AND end_date > NOW(). This query does not filter out soft-deleted markets (where deleted_at IS NOT NULL). A market that has been soft-deleted can still receive new bets because the bet validation query does not check the deleted_at column. Bets placed on deleted markets will never be paid out.
Root Cause
The bet validation query in bets.js was written before the soft delete feature was implemented. It does not include the deleted_at IS NULL condition.
Fix Guide
- Update the bet validation query to add AND deleted_at IS NULL: SELECT * FROM markets WHERE id = AND resolved = FALSE AND end_date > NOW() AND deleted_at IS NULL.
- Return 400 with error: Market is not available for betting if the market is soft-deleted.
- Add a unit test that attempts to place a bet on a soft-deleted market and verifies it returns 400.
- Audit all other market queries in the codebase and add deleted_at IS NULL where missing.
Guidelines
- Key requirement: deleted_at IS NULL Filter / Bet Validation Update / Full Query Audit.
Definition of Done
PR and Checkout
git checkout -b fix/soft-delete-bet-validation
git add .
git commit -m "fix: add deleted_at IS NULL filter to bet validation market query"
git push origin fix/soft-delete-bet-validation
Open a PR against main and include the issue number in the PR description.
Type: BUG
Severity: High
Component: backend/src/routes/bets.js
Context
The POST /api/bets route validates the market with: SELECT * FROM markets WHERE id = AND resolved = FALSE AND end_date > NOW(). This query does not filter out soft-deleted markets (where deleted_at IS NOT NULL). A market that has been soft-deleted can still receive new bets because the bet validation query does not check the deleted_at column. Bets placed on deleted markets will never be paid out.
Root Cause
The bet validation query in bets.js was written before the soft delete feature was implemented. It does not include the deleted_at IS NULL condition.
Fix Guide
Guidelines
Definition of Done
PR and Checkout
git checkout -b fix/soft-delete-bet-validation
git add .
git commit -m "fix: add deleted_at IS NULL filter to bet validation market query"
git push origin fix/soft-delete-bet-validation
Open a PR against main and include the issue number in the PR description.