Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Glemynart/SaaS/llms.txt

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

A GeneratedDocument is the result of merging a DocumentTemplate with the live data of a specific employee. At generation time the service resolves all {{VARIABLE}} placeholders and writes the output into contenidoFinal — an immutable HTML snapshot that never changes even if the employee’s profile or the template is later updated. Once created, a document can be converted to PDF by calling the dedicated render endpoint, which saves the binary to Cloudflare R2 storage, updates the pdfUrl field, and atomically creates an ExpedienteDoc record so the file appears in the employee’s digital file. All endpoints require a valid JWT.
Authorization: Bearer {accessToken}

Generate document

POST /generated-documents/generate
Roles: ADMIN, OPERADOR
Creates a GeneratedDocument record by resolving template variables against the specified employee’s data and the tenant profile. The response contains the rendered contenidoFinal but no PDF yet — call POST /generated-documents/:id/generate-pdf to produce the binary.
employeeId
string (UUID)
required
UUID of the employee whose data populates the template variables.
templateId
string (UUID)
required
UUID of the active DocumentTemplate to render. Returns 400 Bad Request if the template is inactive.
nombre
string
required
Display name for this generated document (e.g. "Contrato Laura Gómez — Marzo 2024").
id
string (UUID)
Identifier of the newly created GeneratedDocument record.
nombre
string
Display name as provided in the request.
tipo
string
Template type inherited from the source template: CONTRACT, CERTIFICATION, LETTER, or MEMO.
contenidoFinal
string
Immutable HTML snapshot with all placeholders already replaced. This field is never recomputed after creation.
pdfUrl
string | null
Always null at this stage. Populated after calling POST /:id/generate-pdf.
employeeId
string (UUID)
Employee associated with this document.
templateId
string (UUID)
Source template identifier.
createdAt
string (ISO 8601)
Creation timestamp.
curl -X POST https://api.oficinaclear.com/generated-documents/generate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "employeeId": "a1b2c3d4-0000-0000-0000-000000000001",
    "templateId": "t1e2m3p-0000-0000-0000-000000000003",
    "nombre": "Certificación laboral — Laura Gómez"
  }'

List generated documents

GET /generated-documents
Roles: ADMIN, OPERADOR, VIEWER
page
number
Page number, minimum 1. Defaults to 1.
limit
number
Records per page, minimum 1. Defaults to 10.
Case-insensitive search across nombre and contenidoFinal.
employeeId
string (UUID)
Restrict results to documents generated for a specific employee.
tipo
string
Filter by document type. One of CONTRACT, CERTIFICATION, LETTER, MEMO.
data
GeneratedDocument[]
Page of document records. Each record includes an embedded employee object (id, primerNombre, segundoNombre, primerApellido, segundoApellido, cedula, cargo, sedeRef) and a template object (id, nombre, tipo).
meta.total
number
Total matching records.
meta.page
number
Current page.
meta.limit
number
Page size.
meta.totalPages
number
Total pages.

Get generated document

GET /generated-documents/:id
Roles: ADMIN, OPERADOR, VIEWER
id
string (UUID)
required
Generated document identifier.
id
string (UUID)
Document identifier.
nombre
string
Display name.
tipo
string
Document type.
contenidoFinal
string
Immutable rendered HTML.
pdfUrl
string | null
R2 URL path of the PDF file, or null if not yet generated.
contratoId
string (UUID) | null
Contract linked to this document, if generated through the contract pipeline.
employee
object
Embedded employee snapshot: id, primerNombre, segundoNombre, primerApellido, segundoApellido, cedula, cargo, tipoDocumento, sedeRef.
template
object
Embedded template snapshot: id, nombre, tipo.
createdAt
string (ISO 8601)
Creation timestamp.

Render PDF

POST /generated-documents/:id/generate-pdf
Roles: ADMIN, OPERADOR
Converts the document’s contenidoFinal HTML into a styled PDF. The rendering pipeline wraps the content in a full HTML page with tenant branding (logo, company name) and employee identification in the header. The resulting binary is saved to Cloudflare R2 and linked back on the document record.
id
string (UUID)
required
Generated document identifier.
id
string (UUID)
Document identifier.
pdfUrl
string
Storage path of the generated PDF (e.g. /uploads/pdfs/{tenantId}-{id}.pdf).
nombre
string
Document display name.
PDF generation and ExpedienteDoc record creation are committed inside a single database transaction. Either both succeed or neither does — you will never end up with an orphaned PDF entry or a missing expediente record.

PDF generation flow

  1. The service fetches the GeneratedDocument and its parent Tenant.
  2. A full HTML document is assembled, with the tenant logo and legal name in the header and the employee’s full name and document number as a subtitle.
  3. The HTML is rendered to a PDF binary via PdfRenderService.
  4. The binary is stored in R2 under the key pdfs/{tenantId}-{id}.pdf.
  5. Inside a single Prisma transaction: pdfUrl is written to the GeneratedDocument row and an ExpedienteDoc record is created, inheriting the contratoId if present.
  6. An audit event PDF_GENERATE is emitted asynchronously.
curl -X POST https://api.oficinaclear.com/generated-documents/g9h8i7j6-0000-0000-0000-000000000004/generate-pdf \
  -H "Authorization: Bearer $TOKEN"

Download PDF

GET /generated-documents/:id/pdf
Roles: ADMIN, OPERADOR, VIEWER
Streams the rendered PDF binary directly from local storage. Returns 404 Not Found if the PDF has not yet been generated or the file cannot be located on disk.
id
string (UUID)
required
Generated document identifier.
The response streams with Content-Type: application/pdf and Content-Disposition: inline; filename="{nombre}.pdf".
curl -o contrato.pdf \
  https://api.oficinaclear.com/generated-documents/g9h8i7j6-0000-0000-0000-000000000004/pdf \
  -H "Authorization: Bearer $TOKEN"

Delete generated document

DELETE /generated-documents/:id
Roles: ADMIN
Permanently removes the GeneratedDocument record. Associated ExpedienteDoc records that reference this document via generatedDocumentId are not automatically removed — delete them separately through DELETE /expediente-docs/:id if needed.
id
string (UUID)
required
Generated document identifier.
id
string (UUID)
Identifier of the deleted record.

Build docs developers (and LLMs) love