Skip to main content

Endpoint

DELETE /api/tanqueos/:id
Permanently delete a fuel tracking record from the system. This operation cannot be undone.

Authentication

Requires JWT authentication token with appropriate permissions.

Path Parameters

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

Response

Returns a confirmation message upon successful deletion.
message
string
Success confirmation message

Examples

Delete a Fuel Record

curl -X DELETE 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'

Success Response Example

Status Code: 200 OK
{
  "message": "Tanqueo eliminado exitosamente"
}

Error Responses

400 Bad Request - Delete Failed

{
  "error": "Cannot delete record due to foreign key constraint"
}
This error occurs if the record is referenced by other tables in the database.

400 Bad Request - Record Not Found

{
  "error": "No record found with the specified ID"
}

401 Unauthorized

{
  "error": "Authentication required"
}

500 Internal Server Error

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

Important Notes

Permanent Deletion

  • This operation permanently removes the record from the tanqueo table
  • There is no soft delete or recovery mechanism
  • Consider creating a backup or export before deleting important records

Foreign Key Constraints

  • If the record is referenced by other tables, the deletion may fail
  • Check for dependencies before attempting to delete
  • The database will prevent deletion if it would violate referential integrity

Audit Trail

  • Once deleted, the record and its audit information (creado_por, actualizado_por) are permanently lost
  • Consider keeping an audit log outside the main table if you need to track deletions

Best Practices

Before Deleting

  1. Verify the record: Use Get By ID to confirm you’re deleting the correct record
  2. Check dependencies: Ensure the record is not referenced elsewhere
  3. Export data: Create a backup if needed for audit purposes
  4. Confirm authorization: Ensure the user has permission to delete this record

Alternative to Deletion

Instead of deleting, consider:
  • Adding a “status” field and marking records as “inactive” or “cancelled”
  • Implementing soft deletes with a deleted_at timestamp
  • Moving records to an archive table

Example Workflow

Verify Before Delete

# Step 1: Get the record to verify
curl -X GET 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer <token>'

# Step 2: Confirm it's the right record, then delete
curl -X DELETE 'https://api.example.com/api/tanqueos/4523' \
  -H 'Authorization: Bearer <token>'

Implementation Details

  • The endpoint executes a DELETE SQL operation on the tanqueo table
  • Row Level Security (RLS) policies may restrict which records can be deleted based on user permissions
  • The operation is atomic - either the record is deleted or an error is returned
  • No cascade deletes are performed - related records in other tables remain unchanged

Build docs developers (and LLMs) love