payment-backoffice/app/services/transactions.ts
2025-12-26 13:10:38 +01:00

57 lines
1.4 KiB
TypeScript

import { getBaseUrl } from "./constants";
import { IHealthData, IFetchHealthDataParams } from "./health";
export async function getTransactions({
transactionType,
query,
}: {
transactionType: string;
query: string;
}) {
const res = await fetch(
`${getBaseUrl()}/api/dashboard/transactions/${transactionType}?${query}`,
{
cache: "no-store",
}
);
if (!res.ok) {
// Handle error from the API
const errorData = await res
.json()
.catch(() => ({ message: "Unknown error" }));
throw new Error(errorData.message || `HTTP error! status: ${res.status}`);
}
return res.json();
}
/**
* Client-side function to fetch health data via the /api/dashboard proxy
*/
export async function getHealthData({
dateStart,
dateEnd,
}: IFetchHealthDataParams = {}): Promise<IHealthData> {
const params = new URLSearchParams();
if (dateStart) params.set("dateStart", dateStart);
if (dateEnd) params.set("dateEnd", dateEnd);
const queryString = params.toString();
const res = await fetch(
`${getBaseUrl()}/api/dashboard${queryString ? `?${queryString}` : ""}`,
{
cache: "no-store",
}
);
if (!res.ok) {
const errorData = await res
.json()
.catch(() => ({ message: "Unknown error" }));
throw new Error(errorData.message || `HTTP error! status: ${res.status}`);
}
return res.json();
}