Skip to main content

PATCH /api/v1/sorteos/:id/open

Transitions a sorteo from SCHEDULED to OPEN status, enabling ticket sales.
Once opened, vendedores can create tickets for this sorteo until it’s closed or the sales cutoff time is reached.

Authentication

Requires ADMIN role.

Path Parameters

id
string
required
UUID of the sorteo to open

Request Body

No request body required.

Response

success
boolean
Indicates if the operation was successful
data
object
The updated sorteo object with status: "OPEN"

Example Request

curl -X PATCH https://api.example.com/api/v1/sorteos/7c9e6679-7425-40de-944b-e07fc1f90ae7/open \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "success": true,
  "data": {
    "id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
    "loteriaId": "550e8400-e29b-41d4-a716-446655440000",
    "scheduledAt": "2025-03-03T12:55:00-06:00",
    "name": "Lotto 12:55 PM",
    "status": "OPEN",
    "digits": 2,
    "isActive": true,
    "reventadoEnabled": true,
    "winningNumber": null,
    "hasWinner": false,
    "createdAt": "2025-03-03T10:00:00-06:00",
    "updatedAt": "2025-03-03T10:30:00-06:00"
  }
}

Error Responses

{
  "success": false,
  "error": "Solo se puede abrir desde SCHEDULED"
}

Opening Requirements

1

Sorteo Must Be Scheduled

Only sorteos with status: "SCHEDULED" can be opened.
2

Sorteo Must Be Active

The sorteo’s isActive field must be true.
3

Admin Permission

Only users with ADMIN role can open sorteos.

Alternative: Force Open

For reopening sorteos from other states, see the Update endpoint for advanced options.
Additional endpoints like force-open and activate-and-open are available but not yet documented. These allow forcefully opening sorteos from any non-evaluated state or reactivating inactive sorteos.

What Happens When Opening?

The sorteo status changes from SCHEDULED to OPEN.
Vendedores can now create tickets for this sorteo through the ticket creation API.
Sorteo cache is cleared to ensure all clients see the updated status.
An activity log entry is created:
{
  "action": "SORTEO_OPEN",
  "targetType": "SORTEO",
  "targetId": "sorteo-uuid",
  "details": {
    "from": "SCHEDULED",
    "to": "OPEN",
    "description": "Sorteo Lotto 12:55 PM (Lotto) del 2025-03-03 12:55:00 -0600 ABIERTO"
  }
}

Sales Cutoff

Sales are automatically cut off based on the loteria’s configuration, typically 5 minutes before the scheduled time.
Example cutoff logic:
const sorteoTime = new Date(sorteo.scheduledAt);
const cutoffMinutes = 5;
const cutoffTime = new Date(sorteoTime.getTime() - (cutoffMinutes * 60 * 1000));

if (currentTime > cutoffTime) {
  throw new Error('Sales closed for this sorteo');
}
The cutoff is enforced at ticket creation time, not when opening the sorteo.

Automated Opening

Sorteos can be opened automatically using the auto-open cron job. See Sorteo Automation for details.
Configuration:
{
  "autoOpenEnabled": true,
  "openCronSchedule": "0 7 * * *"
}

Typical Workflow

1

Create Sorteos

Create sorteos manually or via seed sorteos for upcoming draws.
2

Schedule Auto-Open

Configure auto-open to run at specific times (e.g., 1 AM daily).
3

Sorteos Open Automatically

Sorteos scheduled for today are opened automatically by the cron job.
4

Vendedores Sell Tickets

Vendedores create tickets throughout the day until cutoff time.
5

Close Before Draw

Sales cutoff prevents new tickets close to draw time.
6

Evaluate After Draw

Admin evaluates sorteo with winning number using Evaluate Sorteo.

State Diagram

Close Sorteo

Close an open or evaluated sorteo

Evaluate Sorteo

Set winning number and evaluate

Update Sorteo

Modify sorteo configuration

Create Ticket

Create a ticket for open sorteo

Build docs developers (and LLMs) love