38 lines
968 B
TypeScript
38 lines
968 B
TypeScript
import axios from "axios";
|
|
import { MovimentacaoTribunal } from "@prisma/client";
|
|
|
|
export class TribunalService {
|
|
private apiKey: string;
|
|
|
|
constructor(apiKey: string) {
|
|
this.apiKey = apiKey;
|
|
}
|
|
|
|
async consultarProcesso(
|
|
numero: string,
|
|
tribunal: string,
|
|
): Promise<MovimentacaoTribunal[]> {
|
|
const endpoints = {
|
|
TJ: "https://api.tribunal.jus.br/processo",
|
|
TRT: "https://api.trt.jus.br/processo",
|
|
TRF: "https://api.trf.jus.br/processo",
|
|
};
|
|
|
|
try {
|
|
const response = await axios.get(`${endpoints[tribunal]}/${numero}`, {
|
|
headers: { Authorization: `Bearer ${this.apiKey}` },
|
|
});
|
|
|
|
return this.formatarMovimentacoes(response.data);
|
|
} catch (error) {
|
|
console.error(`Erro ao consultar ${tribunal}:`, error);
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
private formatarMovimentacoes(data: any): MovimentacaoTribunal[] {
|
|
// Implementar formatação específica para cada tribunal
|
|
return [];
|
|
}
|
|
}
|