PATCH /api/v1/sorteos/:id/close
Transitions a sorteo toCLOSED status, marking it as finalized. This operation also cascades to all associated tickets.
Authentication
Requires ADMIN role.Path Parameters
UUID of the sorteo to close
Request Body
No request body required.Response
Indicates if the operation was successful
The updated sorteo object with
status: "CLOSED"Example Request
Example Response
Error Responses
Allowed States for Closing
A sorteo can only be closed from:OPEN
Close without evaluation (no winning number set).Use case: Cancelled or void draws
EVALUATED
Close after evaluation (winning number set, winners identified).Use case: Normal draw completion
Cascade Effect
The close operation:- Updates sorteo status to
CLOSED - Finds all active, non-cancelled tickets for this sorteo
- Marks each ticket with
deletedByCascade: true - Records cascade metadata (source, reason, timestamp)
- Invalidates sorteo cache
What Happens When Closing?
Status Transition
Status Transition
Sorteo status changes to
CLOSED (terminal state).Ticket Cascade
Ticket Cascade
All associated tickets are marked as closed with cascade flags.Query result:
Cache Invalidation
Cache Invalidation
Sorteo cache is cleared to ensure all clients see the updated status.
Activity Logged
Activity Logged
Activity log entry includes cascade count:
Close vs Cancel
- Close (CLOSED)
- Delete/Deactivate
Normal completion of a sorteo lifecycle.
- Sorteo may or may not have winning number
- All tickets are preserved (just marked as cascade-closed)
- Used for normal end-of-life
- Irreversible
Automated Closing
Sorteos can be closed automatically using the auto-close cron job for sorteos with no sales. See Sorteo Automation for details.
- Status is
OPEN - No tickets sold
- Scheduled time has passed
Typical Workflow
Evaluation
Admin evaluates sorteo with winning number via Evaluate.
Winners Pay Out
Winning tickets are paid via Payment API.
When to Close
After All Winners Paid
After All Winners Paid
Best Practice: Close after all winning tickets have been paid out.This ensures:
- Complete payment records
- Accurate financial reporting
- No pending operations
No Sales (Auto-Close)
No Sales (Auto-Close)
Sorteos with zero tickets can be auto-closed to clean up.Prevents:
- Clutter in sorteo lists
- Confusion about active draws
Void/Cancelled Draws
Void/Cancelled Draws
If a draw is cancelled or void, close without evaluation.All tickets remain in their current state (no winners marked).
State Diagram
Related Endpoints
Open Sorteo
Open a sorteo for sales
Evaluate Sorteo
Set winning number before closing
Ticket Payments
Pay winning tickets
Activity Logs
View close operation audit