API Voting & Belum di Integrasikan ke UInya

This commit is contained in:
2025-02-17 22:19:02 +08:00
parent b2edfc4924
commit 42c9b98c86
9 changed files with 238 additions and 163 deletions

View File

@@ -1,14 +1,15 @@
export {
apiGetVoteStatusCountDashboard,
apiGetVoteRiwayatCount
apiGetAdminVoteStatusCountDashboard,
apiGetAdminVoteRiwayatCount,
apiGetAdminVotingByStatus
}
const apiGetVoteStatusCountDashboard = async ({ name }: {
const apiGetAdminVoteStatusCountDashboard = async ({ name }: {
name: "Publish" | "Review" | "Reject";
}) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/voting/dashboard/${name}`, {
const response = await fetch(`/api/admin/vote/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -19,11 +20,11 @@ const apiGetVoteStatusCountDashboard = async ({ name }: {
});
return await response.json().catch(() => null);
}
const apiGetVoteRiwayatCount = async () => {
const apiGetAdminVoteRiwayatCount = async () => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/voting/dashboard/riwayat`, {
const response = await fetch(`/api/admin/vote/dashboard/riwayat`, {
method: "GET",
headers: {
"Content-Type": "application/json",
@@ -33,4 +34,31 @@ const apiGetVoteRiwayatCount = async () => {
}
});
return await response.json().catch(() => null);
}
const apiGetAdminVotingByStatus = async ({
name,
page,
search }: {
name: "Publish" | "Review" | "Reject";
page: string;
search: string;
}) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : "";
const response = await fetch(
`/api/admin/vote/status/${name}${isPage}${isSearch}`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`
}
}
)
return await response.json().catch(() => null);
}