81 lines
2.2 KiB
TypeScript
81 lines
2.2 KiB
TypeScript
import { api } from '../../../services/api';
|
|
import type {
|
|
ApiResponse,
|
|
BancoQuitacao,
|
|
CriarQuitacaoCreditoRequest,
|
|
QuitacaoCreditoHistoricoItem,
|
|
QuitacaoCreditoPreview,
|
|
QuitacaoCreditoPreviewParams,
|
|
QuitacaoCreditoResponse,
|
|
} from '../types/quitacaoCreditoTypes';
|
|
|
|
function unwrapResponse<T>(payload: ApiResponse<T> | T): T {
|
|
if (
|
|
payload &&
|
|
typeof payload === 'object' &&
|
|
'data' in payload &&
|
|
'ok' in payload
|
|
) {
|
|
return (payload as ApiResponse<T>).data;
|
|
}
|
|
|
|
return payload as T;
|
|
}
|
|
|
|
export async function listarBancosCredito(): Promise<BancoQuitacao[]> {
|
|
const response = await api.get<ApiResponse<BancoQuitacao[]> | BancoQuitacao[]>(
|
|
'/quitacoes-credito/bancos-credito'
|
|
);
|
|
|
|
return unwrapResponse<BancoQuitacao[]>(response.data);
|
|
}
|
|
|
|
export async function listarBancosPagamento(): Promise<BancoQuitacao[]> {
|
|
const response = await api.get<ApiResponse<BancoQuitacao[]> | BancoQuitacao[]>(
|
|
'/quitacoes-credito/bancos-pagamento'
|
|
);
|
|
|
|
return unwrapResponse<BancoQuitacao[]>(response.data);
|
|
}
|
|
|
|
export async function buscarPreviewQuitacaoCredito(
|
|
params: QuitacaoCreditoPreviewParams
|
|
): Promise<QuitacaoCreditoPreview> {
|
|
const response = await api.get<ApiResponse<QuitacaoCreditoPreview> | QuitacaoCreditoPreview>(
|
|
'/quitacoes-credito/preview',
|
|
{
|
|
params,
|
|
}
|
|
);
|
|
|
|
return unwrapResponse<QuitacaoCreditoPreview>(response.data);
|
|
}
|
|
|
|
export async function criarQuitacaoCredito(
|
|
data: CriarQuitacaoCreditoRequest
|
|
): Promise<QuitacaoCreditoResponse> {
|
|
const response = await api.post<ApiResponse<QuitacaoCreditoResponse> | QuitacaoCreditoResponse>(
|
|
'/quitacoes-credito',
|
|
data
|
|
);
|
|
|
|
return unwrapResponse<QuitacaoCreditoResponse>(response.data);
|
|
}
|
|
|
|
export async function listarHistoricoQuitacoesCredito(params?: {
|
|
dataInicio?: string;
|
|
dataFim?: string;
|
|
idBancoCredito?: number | '';
|
|
idBancoPagamento?: number | '';
|
|
limite?: number;
|
|
page?: number;
|
|
}): Promise<QuitacaoCreditoHistoricoItem[]> {
|
|
const response = await api.get<
|
|
ApiResponse<QuitacaoCreditoHistoricoItem[]> | QuitacaoCreditoHistoricoItem[]
|
|
>('/quitacoes-credito/historico', {
|
|
params,
|
|
});
|
|
|
|
return unwrapResponse<QuitacaoCreditoHistoricoItem[]>(response.data);
|
|
}
|