Overview
Restriction rules control betting limits across the system with hierarchical priority. Rules can be scoped to Banca, Ventana, or User (vendedor) level, with optional filters for specific numbers, lotteries, sorteos, dates, and times.Rule Hierarchy
Rules are applied using first match wins logic with priority:Priority levels:
- User (vendedor): 100
- Ventana: 10
- Banca: 1
Rule Types
1. Per-Number Limits
Restrict maximum bet amount for specific lottery numbers.2. Global Ticket Limits
Restrict maximum total per ticket (all jugadas combined).3. Sales Cutoff Rules
Define minutes before draw when sales must stop.- RestrictionRule (User → Ventana → Banca)
Loteria.rulesJson.closingTimeBeforeDraw- Default: 5 minutes
4. Date/Time Specific Rules
Apply rules only on specific dates or hours.Creating Rules
Single Number Rule
Batch Number Rules (v1.1.1+)
Create multiple rules for different numbers in a single request.Batch creation rules:
- Maximum 100 numbers per request
- All numbers must be 2 digits (00-99)
- No duplicates allowed
- All rules share same
maxAmount,maxTotal,salesCutoffMinutes - Legacy single-number format still supported:
"number": "25"
Listing Rules
scope:BANCA|VENTANA|USERentityId: UUID of banca/ventana/userloteriaId: Filter by lotterysorteoId: Filter by specific sorteonumber: Filter by specific numberisActive:true|false(default: true)page,pageSize: Pagination
src/api/v1/controllers/restrictionRule.controller.ts:46-72:
My Restrictions (Vendedor View)
Get all effective restrictions for the authenticated vendedor, including inherited rules from ventana and banca.src/api/v1/controllers/restrictionRule.controller.ts:93-230:
Impersonation (ADMIN/VENTANA)
ADMIN and VENTANA users can query restrictions for specific vendedores.Permissions:
- ADMIN: Can query any vendedor
- VENTANA: Can query vendedores in their ventana only
- VENDEDOR:
vendedorIdparameter is ignored, always returns own restrictions
Updating Rules
src/api/v1/controllers/restrictionRule.controller.ts:15-22:
maxAmountmaxTotalsalesCutoffMinutesisActiveappliesToDateappliesToHour
Deleting Rules
src/api/v1/controllers/restrictionRule.controller.ts:24-31:
Deletion is a soft delete (
isActive = false). Rules can be restored.Restoring Rules
src/api/v1/controllers/restrictionRule.controller.ts:33-38:
Automated Rule Management
The system includes a CRON job that automatically manages time-based rules.Check CRON Health
src/api/v1/controllers/restrictionRule.controller.ts:74-77:
Execute CRON Manually
src/api/v1/controllers/restrictionRule.controller.ts:79-82:
Validation During Ticket Creation
Restriction rules are automatically enforced during ticket creation inTicketService.create().
Validation Flow
Fetch applicable rules
System fetches all rules matching:
- User/Ventana/Banca hierarchy
loteriaIdsorteoId(if specified)appliesToDate(if specified)appliesToHour(if specified)
Sort by priority
Rules are sorted:
- Priority level (100 → 10 → 1)
- Specificity (number-specific before global)
Apply first matching rule
For each jugada, find first rule where:
numbermatches (or rule hasnumber = null)- All time/date filters pass
maxAmount limit.Common Patterns
Limit Popular Numbers Across System
Vendor-Specific Limit for High Risk
Event-Specific Restriction
Extended Cutoff for Specific Sorteo
Best Practices
Use batch creation for number patterns
Use batch creation for number patterns
When setting limits for multiple numbers with same restriction, use array format to reduce API calls.
Start with banca-level defaults
Start with banca-level defaults
Establish baseline limits at BANCA scope, then override for specific ventanas or users as needed.
Monitor with /me endpoint
Monitor with /me endpoint
Vendedores should call
/restrictions/me on login to cache their effective limits client-side.Include reasons for changes
Include reasons for changes
Always include
reason when deleting or updating rules for audit compliance.Test with low values first
Test with low values first
When creating new rules, start with conservative (low)
maxAmount values and adjust based on actual sales patterns.Related Guides
- Ticket Creation - Understanding how restrictions are enforced
- Sorteo Management - Setting up draw schedules
- Analytics - Monitoring exposure and risk