List company documents
GET/company/documents
Retrieves a paginated list of all documents associated with the authenticated user's company.
Operation Flow:
- Authentication via a valid JWT with a manager role or higher.
- Validation of pagination parameters.
- Optional filtering by document type.
- Paginated database query (only the latest version of each document).
- Return of documents with metadata and file paths.
Access Requirements:
- Authentication: Valid JWT token (Bearer token)
- Minimum Role: Company Manager (isGestor)
- Permissions: Access only to documents of the user's own company.
Typical Use Cases:
- Consult company invoices and contracts.
- Filter documents by category (documentType).
- Review the approval status of pending documents.
- Access recent version history.
Document Statuses:
pending: Pending review by administration.approved: Approved and available for use.rejected: Rejected with a specified reason.
Important Considerations:
- Returns only the latest version of each document (excludes obsolete versions where
newVersion: null). - All timestamps are in UTC format.
- Maximum of 100 documents per page.
- Sorted by creation date in descending order (most recent first).
- Files are stored in S3/MinIO with relative paths in
filePaths.
Example Request:
GET /company/documents?page=1&limit=25&documentType=648ac82b769e704acd2c73f5
Authorization: Bearer {token}
Example Successful Response:
\{
docs: [
\{
_id: 5f8d3b7a9c2d1e0f4a6b5c4d,
name: Invoice Q1 2023,
status: approved,
documentType: 5f8d3b7a9c2d1e0f4a6b5c4e,
version: 1,
filePaths: [documents/company1/invoice_q1.pdf],
createdAt: 2023-04-15T09:30:00.000Z,
updatedAt: 2023-04-20T14:15:00.000Z
\}
],
totalDocs: 15,
limit:
<Heading
id={"request"}
as={"h2"}
className={"openapi-tabs__heading"}
children={"Request"}
>
</Heading>
<ParamsDetails
parameters={[{"name":"page","in":"query","description":"Page number for navigation in paginated results.\nUseful for dividing the display when there are many documents.","required":false,"example":1,"schema":{"type":"integer","minimum":1,"default":1}},{"name":"limit","in":"query","description":"Maximum number of documents to return per page.\nAllows balancing performance (low values) vs convenience (high values).","required":false,"example":25,"schema":{"type":"integer","minimum":1,"maximum":100,"default":10}},{"name":"documentType","in":"query","description":"Filter documents by specific type using its MongoDB ID.\nAvailable types are obtained from the /documents/types endpoint.\nUseful for displaying only invoices, contracts, or other categories.","required":false,"example":"648ac82b769e704acd2c73f5","schema":{"type":"string","format":"ObjectId","pattern":"^[a-f0-9]{24}$"}}]}
>
</ParamsDetails>
<RequestSchema
title={"Body"}
body={undefined}
>
</RequestSchema>
<StatusCodes
id={undefined}
label={undefined}
responses={{"200":{"description":"List of documents obtained successfully","content":{"application/json":{"schema":{"type":"object","description":"Paged response with list of company documents","properties":{"docs":{"type":"array","description":"List of documents on the current page","items":{"type":"object","description":"It represents a corporate document with its metadata.","properties":{"_id":{"type":"string","description":"Unique document identifier (MongoDB ObjectId)","format":"ObjectId","pattern":"^[a-f0-9]{24}$","example":"5f8d3b7a9c2d1e0f4a6b5c4d"},"name":{"type":"string","description":"Descriptive document name","minLength":3,"maxLength":100,"example":"Factura Q1 2023"},"status":{"type":"string","description":"Document Approval Status","enum":["pending","approved","rejected"],"example":"approved"},"documentType":{"type":"string","description":"Document type ID (reference to /documents/types)","format":"ObjectId","pattern":"^[a-f0-9]{24}$","example":"5f8d3b7a9c2d1e0f4a6b5c4e"},"version":{"type":"integer","description":"Document version number","minimum":1,"example":1},"filePaths":{"type":"array","description":"S3/MinIO file paths (relative to the bucket)","items":{"type":"string"},"example":["documents/company1/factura_q1.pdf","documents/company1/anexo.pdf"]},"previousVersion":{"type":"string","description":"Previous version ID (null if it is the first version)","format":"ObjectId","pattern":"^[a-f0-9]{24}$","nullable":true,"example":null},"createdAt":{"type":"string","description":"Document creation date (UTC)","format":"date-time","example":"2023-04-15T09:30:00.000Z"},"updatedAt":{"type":"string","description":"Last Updated Date (UTC)","format":"date-time","example":"2023-04-20T14:15:00.000Z"}},"title":"Document"}},"totalDocs":{"type":"integer","description":"Total documents found (all pages)","example":15},"limit":{"type":"integer","description":"Documents per page limit","example":10},"page":{"type":"integer","description":"Current page","example":1},"totalPages":{"type":"integer","description":"Total available pages","example":2}},"title":"DocumentsPaginatedResponse"},"example":{"docs":[{"_id":"5f8d3b7a9c2d1e0f4a6b5c4d","name":"Factura Q1 2023","status":"approved","documentType":"5f8d3b7a9c2d1e0f4a6b5c4e","version":1,"filePaths":["documents/company1/factura_q1.pdf"],"createdAt":"2023-04-15T09:30:00.000Z","updatedAt":"2023-04-20T14:15:00.000Z"},{"_id":"5f8d3b7a9c2d1e0f4a6b5c4f","name":"Contrato de Servicios","status":"pending","documentType":"5f8d3b7a9c2d1e0f4a6b5c50","version":2,"filePaths":["documents/company1/contrato_v2.pdf","documents/company1/anexo.pdf"],"createdAt":"2023-05-10T11:20:00.000Z","updatedAt":"2023-05-12T16:45:00.000Z"}],"totalDocs":15,"limit":10,"page":1,"totalPages":2}}}},"401":{"description":"Unauthorized - Invalid or missing JWT token","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","enum":["NO_TOKEN","TOKEN_NOT_VALID"]}}},"example":{"error":"NO_TOKEN"}}}},"403":{"description":"Forbidden - Insufficient permissions","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"}}},"example":{"error":"NOT_ALLOWED"}}}}}}
>
</StatusCodes>