Skip to main content

Endpoint

PUT /api/tanqueos/:id
Update an existing fuel tracking record. All fields from the create operation can be updated, including changing the operation type between TANQUEO and ANTICIPO.

Authentication

Requires JWT authentication token. The authenticated user’s ID is automatically recorded as actualizado_por.

Path Parameters

id
number
required
The unique identifier of the fuel record to update

Request Body

Same fields as Create Fuel Record, all optional but should include the fields you want to update.

Common Fields

fecha
string
Transaction date in format YYYY-MM-DD
bomba_id
number
Fuel station identifier
area_operacion_id
number
Operational area identifier
concepto
string
Concept: OPERATIVO or ADMINISTRATIVO
tipo_operacion
string
Operation type: TANQUEO or ANTICIPO
observacion
string
Notes or observations
saldo_disponible
number
Available balance at fuel station

TANQUEO-Specific Fields

conductor_id
number
Driver identifier
placa_id
number
Vehicle plate identifier
tipo_combustible
string
Fuel type: ACPM, GASOLINA, or EXTRA
valor_tanqueo
number
Total fuel cost in COP
cantidad_galones
number
Quantity of fuel in gallons
horometro
number
Hourmeter reading

ANTICIPO-Specific Fields

valor_anticipo
number
Advance payment amount in COP

Response

Returns the updated fuel record with all fields.
id
number
Record identifier
fecha
string
Transaction date
conductor_id
number | null
Driver identifier
placa_id
number | null
Vehicle plate identifier
bomba_id
number
Fuel station identifier
area_operacion_id
number
Operational area identifier
tipo_combustible
string | null
Fuel type
valor_tanqueo
number | null
Total fuel cost
cantidad_galones
number | null
Fuel quantity in gallons
costo_por_galon
number | null
Automatically recalculated cost per gallon
horometro
number | null
Hourmeter reading
valor_anticipo
number | null
Advance payment amount
saldo_disponible
number | null
Available balance
concepto
string
Concept
tipo_operacion
string
Operation type
observacion
string | null
Observations
creado_por
string
User ID who created the record (unchanged)
actualizado_por
string
User ID who last updated the record
actualizado_en
string
Timestamp of last update (ISO 8601 format)

Examples

Update Fuel Amount and Cost

curl -X PUT 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{
    "valor_tanqueo": 175000,
    "cantidad_galones": 14.2,
    "observacion": "Cantidad corregida"
  }'

Add Hourmeter Reading

curl -X PUT 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{
    "horometro": 1250.5
  }'

Convert TANQUEO to ANTICIPO

curl -X PUT 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{
    "tipo_operacion": "ANTICIPO",
    "valor_anticipo": 500000
  }'

Change Driver and Vehicle

curl -X PUT 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' \
  -H 'Content-Type: application/json' \
  -d '{
    "conductor_id": 55,
    "placa_id": 201,
    "observacion": "Conductor y vehículo corregidos"
  }'

Success Response Example

Status Code: 200 OK
{
  "id": 4523,
  "fecha": "2024-03-15",
  "conductor_id": 42,
  "placa_id": 156,
  "bomba_id": 7,
  "area_operacion_id": 2,
  "tipo_combustible": "ACPM",
  "valor_tanqueo": 175000,
  "cantidad_galones": 14.2,
  "costo_por_galon": 12323.94,
  "horometro": 1250.5,
  "valor_anticipo": null,
  "saldo_disponible": 2500000,
  "concepto": "OPERATIVO",
  "tipo_operacion": "TANQUEO",
  "observacion": "Cantidad corregida",
  "creado_por": "550e8400-e29b-41d4-a716-446655440000",
  "actualizado_por": "550e8400-e29b-41d4-a716-446655440000",
  "actualizado_en": "2024-03-16T14:30:22.123Z"
}

Update Behavior

Type Conversion Handling

When changing tipo_operacion: TANQUEO → ANTICIPO:
  • Vehicle and driver fields are set to null
  • tipo_combustible, valor_tanqueo, cantidad_galones, horometro, costo_por_galon are nullified
  • valor_anticipo must be provided
ANTICIPO → TANQUEO:
  • valor_anticipo is set to null
  • Required TANQUEO fields must be provided: conductor_id, placa_id, tipo_combustible, valor_tanqueo, cantidad_galones

Automatic Updates

  • costo_por_galon: Recalculated automatically when valor_tanqueo or cantidad_galones changes
  • actualizado_por: Set to authenticated user’s ID from JWT token
  • actualizado_en: Set to current server timestamp (ISO 8601 format)

Default Values

  • tipo_combustible: Defaults to “ACPM” if not specified for TANQUEO
  • Other fields retain their existing values if not included in the update request

Error Responses

400 Bad Request - Invalid Field

{
  "error": "invalid input syntax for type numeric: \"abc\""
}

400 Bad Request - Foreign Key Violation

{
  "error": "update on table \"tanqueo\" violates foreign key constraint"
}

404 Not Found

{
  "error": "Tanqueo no encontrado"
}

401 Unauthorized

{
  "error": "Authentication required"
}

500 Internal Server Error

{
  "error": "Error en el servidor"
}

Validation Rules

  • The record with the specified id must exist
  • Foreign key constraints are enforced (bomba_id, area_operacion_id, conductor_id, placa_id must reference valid records)
  • Type-specific fields are validated based on tipo_operacion
  • Numeric fields must be valid numbers
  • Date must be in YYYY-MM-DD format

Implementation Notes

  • Partial updates are supported - only include fields you want to change
  • The update is transactional - either all changes succeed or none are applied
  • Audit fields (actualizado_por, actualizado_en) are automatically managed
  • The original creator (creado_por) is never changed
  • Cost per gallon is recalculated server-side to maintain consistency

Build docs developers (and LLMs) love