Skip to main content

Overview

Retrieve the hierarchical commission policy JSON for a specific entity. Policies define commission percentages based on lottery, bet type, and multiplier ranges.

Endpoints

Get Banca Policy

GET /api/v1/bancas/:id/commission-policy
Authorization: ADMIN only

Get Ventana Policy

GET /api/v1/ventanas/:id/commission-policy
Authorization: ADMIN can view any ventana, VENTANA can view their own

Get User Policy

GET /api/v1/users/:id/commission-policy
Authorization: ADMIN, or the user themselves, or VENTANA viewing their vendor

Path Parameters

id
string
required
UUID of the banca, ventana, or user

Response

success
boolean
Indicates if the request was successful
data
object
Entity details with commission policy

Examples

curl -X GET "https://api.example.com/api/v1/bancas/550e8400-e29b-41d4-a716-446655440000/commission-policy" \
  -H "Authorization: Bearer YOUR_TOKEN"

Response Example

{
  "success": true,
  "data": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "name": "Banca Central",
    "code": "BC001",
    "commissionPolicyJson": {
      "version": 1,
      "effectiveFrom": "2025-01-01T00:00:00.000Z",
      "effectiveTo": null,
      "defaultPercent": 5.0,
      "rules": [
        {
          "id": "rule-uuid-1",
          "loteriaId": "loteria-uuid",
          "betType": "NUMERO",
          "multiplierId": "multiplier-uuid",
          "multiplierRange": { "min": 80, "max": 80 },
          "percent": 8.5,
          "multiplier": {
            "id": "multiplier-uuid",
            "name": "Base 80x",
            "valueX": 80,
            "kind": "NUMERO",
            "loteriaId": "loteria-uuid",
            "isActive": true
          }
        },
        {
          "id": "rule-uuid-2",
          "loteriaId": null,
          "betType": "REVENTADO",
          "multiplierId": null,
          "multiplierRange": { "min": 0, "max": 999 },
          "percent": 12.0,
          "multiplier": null
        }
      ]
    }
  }
}

Resolution Priority

Commission policies follow a hierarchical resolution with first match wins:
  1. USER policy (highest priority)
  2. VENTANA policy
  3. BANCA policy (lowest priority)
Within each policy, rules are evaluated in array order. The first rule matching all conditions (loteriaId, betType, multiplier range) is used.
The embedded multiplier object is populated by the backend for frontend convenience. It represents the actual multiplier entity that matches the rule’s criteria.

Error Responses

{
  "success": false,
  "error": "Banca no encontrada",
  "code": "BANCA_NOT_FOUND"
}

Set Commission Policy

Update commission policy configuration

Commission Analytics

View commission metrics and reports

Implementation Details

From src/api/v1/controllers/commission.controller.ts:136-162:
async getBancaCommissionPolicy(req: AuthenticatedRequest, res: Response) {
  const { id } = req.params;

  const banca = await prisma.banca.findUnique({
    where: { id },
    select: {
      id: true,
      name: true,
      code: true,
      commissionPolicyJson: true,
    },
  });

  if (!banca) {
    throw new AppError("Banca no encontrada", 404, { code: "BANCA_NOT_FOUND" });
  }

  const commissionPolicyJson = await embedMultipliersInPolicy(banca.commissionPolicyJson);
  return success(res, { ...banca, commissionPolicyJson });
}
The embedMultipliersInPolicy helper performs a single batch query to fetch all related multipliers and embed them in the policy rules for frontend hydration.

Build docs developers (and LLMs) love