Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/tutosrive/factus_challenge/llms.txt

Use this file to discover all available pages before exploring further.

This endpoint dynamically builds an INSERT statement from the JSON body and executes it against the specified PostgreSQL table. Column names are derived from the object’s keys (get_keys_dict) and values are serialised into the SQL value list (generate_str_of_dict). The newly inserted row is returned via RETURNING *, so the caller immediately receives the full database record — including any auto-generated id, timestamps, or default values.

Endpoint

POST /add-data/:table

Path Parameters

table
string
required
Name of the PostgreSQL table to insert into. Examples: customer, products.

Request Body

Send a JSON object where each key is a column name and each value is the data to insert into that column. The controller uses two helpers to build the SQL:
  • get_keys_dict(data) — extracts the keys in insertion order to form the column list.
  • generate_str_of_dict(data, false) — serialises the values: string values are automatically wrapped in single quotes; numeric values are left bare.
The resulting SQL executed against PostgreSQL is:
INSERT INTO {table}({cols}) VALUES({values}) RETURNING *
names
string
Full name of the customer (example field).
address
string
Street address (example field).
email
string
Contact email address (example field).
phone
string
Phone number (example field).
tribute_id
number
Foreign key to customer_tribute (example field — sent as a number, not quoted in SQL).
municipality_id
number
Foreign key to municipality (example field).
identification
string
Document / identification number (example field).
type_id
number
Foreign key to identification_document (example field).
id_org
number
Foreign key to legal_organization (example field).
The body fields above correspond to the customer table used in the reference implementation. When inserting into a different table, simply change the keys to match that table’s column names. There is no server-side schema validation — the PostgreSQL driver will reject mismatched columns with a 500 error.

Responses

200 — OK

Returned when rowCount > 0 (the row was inserted successfully).
{
  "status": 200,
  "message": "Datos agregados",
  "data": { /* inserted row object */ }
}
status
number
Always 200 on success.
message
string
"Datos agregados"
data
object
The full inserted row as returned by RETURNING *. Contains all column values, including database-generated ones such as id or created_at.

404 — Not Found

Returned when rowCount === 0 (the insert ran but affected no rows — unusual for a standard INSERT).
{
  "status": 404,
  "message": "No se agregaron los datos"
}

500 — Internal Server Error

Returned on any exception thrown by the pg driver (e.g., a NOT NULL violation, a foreign-key constraint failure, or a connection error).
{
  "status": 500,
  "message": "Error al agregar los datos",
  "error": { /* pg error object */ }
}
error
object
Raw error from the pg driver. Inspect error.code and error.detail for PostgreSQL error specifics.

Examples

curl -X POST http://localhost:3000/add-data/customer \
  -H "Content-Type: application/json" \
  -d '{
    "names": "Santiago Rivera",
    "address": "Cll. 22 #45C-45",
    "email": "[email protected]",
    "phone": "3103362199",
    "tribute_id": 21,
    "municipality_id": 1041,
    "identification": "1109780065",
    "type_id": 3,
    "id_org": 2
  }'

Example Response

{
  "status": 200,
  "message": "Datos agregados",
  "data": {
    "id": 7,
    "names": "Santiago Rivera",
    "address": "Cll. 22 #45C-45",
    "email": "[email protected]",
    "phone": "3103362199",
    "tribute_id": 21,
    "municipality_id": 1041,
    "identification": "1109780065",
    "type_id": 3,
    "id_org": 2
  }
}

String quoting is automatic. The generate_str_of_dict helper inspects each value’s JavaScript type before building the SQL string. Values whose typeof is "string" are wrapped in single quotes (e.g., 'Santiago Rivera'); values whose typeof is "number" are inserted as bare literals (e.g., 21). Always send numeric foreign keys as JSON numbers — not as quoted strings — to avoid type mismatches in PostgreSQL.

Build docs developers (and LLMs) love