Proveedores API
The Proveedores (Suppliers) API provides complete CRUD operations for managing supplier information in the POS system. Suppliers are registered with their business details, contact information, and are linked to cities for geographical organization.Endpoints Overview
| Method | Endpoint | Authentication | Description |
|---|---|---|---|
| POST | /api/pos/proveedor | Required | Create a new supplier |
| GET | /api/pos/proveedor | Required | Get all suppliers with pagination |
| GET | /api/pos/proveedor/search | Required | Search suppliers by name or RUC |
| GET | /api/pos/proveedor/:id | Required | Get supplier by ID |
| PUT | /api/pos/proveedor/:id | Required | Update supplier information |
| DELETE | /api/pos/proveedor/:id | Required | Soft delete supplier (marks as inactive) |
POST /api/pos/proveedor
Create a new supplier in the system. All fields are validated using the proveedor DTO schema before insertion.All authenticated requests must include a valid JWT token in the Authorization header.
Request
Company business name. Must be between 7 and 120 characters.
Tax identification number (RUC). Must be exactly 13 numeric digits. Must be unique across all suppliers.
Landline phone number. Maximum 10 numeric digits.
Mobile phone number. Maximum 9 numeric digits.
Email address. Must be valid email format, maximum 60 characters.
Physical address. Between 5 and 60 characters.
City code (foreign key). Must reference a valid city in the database.
Supplier status. Valid values:
ACT (Active), INA (Inactive). Defaults to ACT.Registration date. Defaults to current date if not provided.
Response
Auto-generated unique supplier code
Company business name
Tax identification number
Landline phone number
Mobile phone number
Email address
Physical address
City code
Supplier status (ACT/INA)
Registration date
Example Request
Response Examples
Success Response (201 Created)
Success Response (201 Created)
Validation Error (400)
Validation Error (400)
Validation errors are returned as an array when the request body doesn’t meet DTO validation requirements.
Duplicate RUC (400)
Duplicate RUC (400)
Invalid City (400)
Invalid City (400)
GET /api/pos/proveedor
Retrieve a paginated list of all active suppliers. Supports search functionality by business name or RUC.Query Parameters
Page number for pagination
Number of records per page
Search term to filter by business name or RUC (case-insensitive)
Response
Array of supplier objects
Total number of suppliers matching the search criteria
Current page number
Total number of pages
Number of records per page
Example Request
Response Example
Success Response (200 OK)
Success Response (200 OK)
GET /api/pos/proveedor/search
Fast search endpoint for finding suppliers by business name or RUC. Returns a simplified list limited to 20 results for autocomplete functionality.This endpoint is designed for quick searches and autocomplete features. It returns only basic supplier information and is limited to 20 results.
Query Parameters
Search term to match against business name or RUC (case-insensitive)
Response
Returns an array of supplier objects with basic information:Supplier code
Company business name
Tax identification number
Status (ACT/INA)
Example Request
Response Examples
Success Response (200 OK)
Success Response (200 OK)
Missing Parameter (400)
Missing Parameter (400)
GET /api/pos/proveedor/:id
Retrieve detailed information for a specific supplier by their unique code.Path Parameters
The unique supplier code (e.g., PRV000123)
Response
Returns the complete supplier object with all fields.Example Request
Response Examples
Success Response (200 OK)
Success Response (200 OK)
Not Found (404)
Not Found (404)
PUT /api/pos/proveedor/:id
Update supplier information. All fields are optional; only provided fields will be updated using COALESCE in the SQL query.Path Parameters
The unique supplier code to update
Request
Company business name (min 7 characters)
Tax identification number (13 digits)
Landline phone number (max 10 digits)
Mobile phone number (max 9 digits)
Email address
Physical address
City code
Supplier status (ACT/INA)
Response
Returns the complete updated supplier object.Example Request
Response Example
Success Response (200 OK)
Success Response (200 OK)
DELETE /api/pos/proveedor/:id
Soft delete a supplier by marking it as inactive (prv_estado = ‘INA’). The supplier record is not physically removed from the database.Path Parameters
The unique supplier code to delete
Response
Returns 204 No Content on successful deletion.Example Request
Error Codes
| Status Code | Description |
|---|---|
| 200 | Request successful |
| 201 | Resource created successfully |
| 204 | Resource deleted successfully (no content) |
| 400 | Bad request - validation errors or constraint violations |
| 404 | Supplier not found |
| 500 | Internal server error |
Database Constraints
Key Database Constraints:
prv_rucandprv_razonsocialmust be unique across all suppliersct_codigomust reference a valid city in the ciudad table- Only active suppliers (
prv_estado = 'ACT') are returned in listing endpoints - Supplier codes are auto-generated by the database
Implementation Notes
The Proveedores API uses connection pooling with user-specific database credentials extracted from the JWT token. Each request:- Extracts credentials from
req.user(populated byverifyTokenmiddleware) - Creates a dedicated connection pool using those credentials
- Executes the database operation
- Closes the connection pool in the
finallyblock