API de Documentos
Endpoints para gerenciamento completo de documentos arquivísticos.
document.list
Lista documentos com filtros e paginação.
Tipo: Query (GET)
Autenticação: Opcional (público retorna apenas documentos públicos)
Input
typescript
{
search?: string;
documentTypeId?: string;
accessLevel?: string;
insertionDateStart?: string; // YYYY-MM-DD
insertionDateEnd?: string; // YYYY-MM-DD
page?: number; // Default: 1
limit?: number; // Default: 10
}Response
typescript
{
documents: Array<{
id: number;
digitalId: string;
title: string;
documentTypeId: string;
documentType: { name: string };
accessLevel: string;
createdAt: Date;
updatedAt: Date;
// ... campos dinâmicos
}>;
total: number;
page: number;
limit: number;
totalPages: number;
}Exemplo
typescript
const { data } = await trpc.document.list.useQuery({
search: "relatório",
accessLevel: "Público",
page: 1,
limit: 10
});document.getById
Busca documento específico por ID.
Tipo: Query (GET)
Autenticação: Opcional (acesso baseado em nível)
Input
typescript
{
id: number;
}Response
typescript
{
id: number;
digitalId: string;
title: string;
fields: Array<{
fieldConfigId: string;
value: string;
fieldConfig: {
fieldKey: string;
fieldName: string;
}
}>;
attachments: Array<{
id: string;
fileName: string;
fileSize: bigint;
r2FileKey: string;
}>;
// ... outros campos
}document.create
Cria novo documento.
Tipo: Mutation (POST)
Autenticação: Obrigatória
Input
typescript
{
title?: string;
documentTypeId?: string;
accessLevel?: string;
attachmentFileIds?: string[];
// ... campos dinâmicos
}Response
typescript
{
id: number;
digitalId: string;
title: string;
createdAt: Date;
}Exemplo
typescript
const create = trpc.document.create.useMutation();
await create.mutateAsync({
title: "Relatório Anual 2024",
documentTypeId: "uuid",
accessLevel: "Público"
});document.update
Atualiza documento existente.
Tipo: Mutation (POST)
Autenticação: Obrigatória
Input
typescript
{
id: number;
title?: string;
documentTypeId?: string;
accessLevel?: string;
attachmentFileIds?: string[];
// ... campos dinâmicos
}document.delete
Exclui documento (soft delete).
Tipo: Mutation (POST)
Autenticação: Obrigatória
Input
typescript
{
id: number;
}Response
typescript
{
success: true;
message: "Documento excluído com sucesso"
}document.reindexSearch
Reindexareindex todos os documentos no Sonic.
Tipo: Mutation (POST)
Autenticação: Admin/Super apenas
Response
typescript
{
success: true;
message: "Reindexação concluída com sucesso"
}document.getSearchSuggestions
Retorna sugestões de busca baseadas no índice.
Tipo: Query (GET)
Autenticação: Não requerida
Input
typescript
{
word: string; // Min: 1 caractere
limit?: number; // Default: 5
}Response
typescript
string[] // Array de sugestõesExemplo
typescript
const { data: suggestions } = trpc.document.getSearchSuggestions.useQuery({
word: "rel",
limit: 5
});
// ["relatório", "relação", "relacional", ...]Erros Comuns
NOT_FOUND (404)
json
{
"error": {
"code": "NOT_FOUND",
"message": "Documento não encontrado"
}
}FORBIDDEN (403)
json
{
"error": {
"code": "FORBIDDEN",
"message": "Sem permissão para acessar este documento"
}
}CONFLICT (409)
json
{
"error": {
"code": "CONFLICT",
"message": "Documento com este ID Digital já existe"
}
}