Skip to main content

PATCH /api/v1/loterias/:id

Updates an existing loteria’s configuration. Changes to isActive will cascade to associated sorteos.
Changing isActive affects all sorteos for this loteria. Deactivating cascades to sorteos, activating restores them.

Authentication

Requires authentication. Typically ADMIN role for updates.

Path Parameters

id
string
required
UUID of the loteria to update

Request Body

All fields are optional. Only provided fields will be updated.
name
string
Update the loteria name.Min: 2 characters
Name must be unique across all loterias.
rulesJson
object
Update configuration rules.See Create Loteria for full schema.
isActive
boolean
Activate or deactivate the loteria.
Changing this field triggers cascade operations on all associated sorteos.

Response

success
boolean
Indicates if the operation was successful
data
object
The updated loteria object

Example Request

curl -X PATCH https://api.example.com/api/v1/loterias/550e8400-e29b-41d4-a716-446655440000 \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "rulesJson": {
      "digits": 2,
      "drawSchedule": {
        "frequency": "diario",
        "times": ["12:55", "18:55", "20:55"]
      },
      "reventadoConfig": {
        "enabled": true
      },
      "autoCreateSorteos": true
    }
  }'

Example Response

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Lotto",
    "rulesJson": {
      "digits": 2,
      "drawSchedule": {
        "frequency": "diario",
        "times": ["12:55", "18:55", "20:55"]
      },
      "reventadoConfig": {
        "enabled": true
      },
      "autoCreateSorteos": true
    },
    "isActive": true,
    "createdAt": "2025-03-03T10:00:00-06:00",
    "updatedAt": "2025-03-03T14:30:00-06:00"
  }
}

Error Responses

{
  "success": false,
  "error": "Lotería not found"
}

Cascade Effects

Changes to isActive trigger automatic cascade operations on all associated sorteos.
Setting isActive: falseCascade effect:
  1. Loteria is marked inactive
  2. All SCHEDULED sorteos are marked isActive: false
  3. Sorteos remain in database but hidden from vendedores
  4. Existing tickets remain valid
Activity log:
{
  "action": "LOTERIA_UPDATE",
  "details": {
    "isActive": false,
    "sorteosAffected": 45,
    "description": "Estado cambiado a INACTIVO. Sorteos afectados: 45"
  }
}

Common Update Scenarios

Add a third daily draw:
{
  "rulesJson": {
    "drawSchedule": {
      "frequency": "diario",
      "times": ["12:55", "18:55", "20:55"]
    }
  }
}
Effect:
  • New sorteos will be created at 20:55
  • Existing sorteos unchanged
  • Next seed will include new time
Turn on REVENTADO feature:
{
  "rulesJson": {
    "reventadoConfig": {
      "enabled": true
    }
  }
}
Effect:
  • New sorteos will have reventadoEnabled: true
  • Existing sorteos unchanged
  • Vendedores can sell REVENTADO bets on new sorteos
Switch from Times (2) to Monazos (3):
{
  "rulesJson": {
    "digits": 3
  }
}
This is a significant change. Ensure multipliers are updated accordingly.
Effect:
  • New sorteos inherit digits: 3
  • Existing sorteos keep their original digits
  • Winning numbers must be 000-999 for new sorteos
Stop automatic sorteo generation:
{
  "rulesJson": {
    "autoCreateSorteos": false
  }
}
Effect:
  • Cron job skips this loteria
  • Sorteos must be created manually
  • Useful for irregular or special draws

Partial Updates

rulesJson is merged with existing rules. Only specified fields are updated.
Example: Update only draw times without changing other rules:
{
  "rulesJson": {
    "drawSchedule": {
      "times": ["14:00", "20:00"]
    }
  }
}
This updates times but preserves frequency, digits, reventadoConfig, etc.

Activity Logging

All updates are logged:
{
  "action": "LOTERIA_UPDATE",
  "targetType": "LOTERIA",
  "targetId": "loteria-uuid",
  "details": {
    "name": "Lotto",
    "sorteosAffected": 0,
    "description": "Lotería actualizada: Lotto"
  }
}
With cascade:
{
  "action": "LOTERIA_UPDATE",
  "details": {
    "isActive": false,
    "sorteosAffected": 45,
    "sorteosIds": ["sorteo-1", "sorteo-2", "..."],
    "description": "Estado cambiado a INACTIVO. Sorteos afectados: 45"
  }
}

Best Practices

1

Preview Before Seeding

After updating drawSchedule, use Preview Schedule to verify changes.
2

Test with Inactive

When making significant changes, set isActive: false first to test without affecting vendedores.
3

Update Multipliers

If changing digits, also update multiplier values to match the new number range.
4

Communicate Changes

Notify vendedores when changing schedules or enabling/disabling features.

Get Loteria

View current configuration

Preview Schedule

See effect of schedule changes

Seed Sorteos

Generate sorteos with new rules

Activity Logs

View update history

Build docs developers (and LLMs) love