Skip to content

Commit

Permalink
feat : add getTransactions helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
ad956 committed Aug 8, 2024
1 parent b6636b8 commit 47ebc12
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
30 changes: 30 additions & 0 deletions app/lib/admin/getTransactions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use server";
import { getSessionToken } from "../sessions/sessionUtils";
import getBaseUrl from "@utils/getBaseUrl";

export default async function getTransactions() {
const session = getSessionToken();
const serverUrl = getBaseUrl();

const headers = {
Authorization: `Bearer ${session}`,
};
try {
const res = await fetch(`${serverUrl}/api/admin/transactions`, {
headers,
// cache: "no-cache",
});

if (!res.ok) {
console.error(`Error fetching transactions data: ${res.statusText}`);
throw new Error("fetching transactions data");
}

const transactionsData = await res.json();

return transactionsData;
} catch (error) {
console.error("An error occurred while fetching transactions data:", error);
throw error;
}
}
9 changes: 8 additions & 1 deletion app/lib/admin/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import addAdmin from "./addAdmin";
import getAdminData from "./getAdminData";
import { getTilesData, getRecentUsersData } from "./getDashboardData";
import getTransactions from "./getTransactions";

export { addAdmin, getAdminData, getTilesData, getRecentUsersData };
export {
addAdmin,
getAdminData,
getTilesData,
getRecentUsersData,
getTransactions,
};

0 comments on commit 47ebc12

Please sign in to comment.