fix admin voting

- fix detail publish voting
This commit is contained in:
2025-03-24 13:53:57 +08:00
parent 5a220528d2
commit c0f35a4c96
15 changed files with 577 additions and 97 deletions

View File

@@ -3,6 +3,8 @@ export {
apiGetAdminVoteRiwayatCount,
apiGetAdminVotingByStatus,
apiGetAdminVotingRiwayat,
apiGetOneAdminVotingById as apiGetOneVotingById,
apiGetAdminKontibutorVotingById,
};
const apiGetAdminVoteStatusCountDashboard = async ({
name,
@@ -87,7 +89,6 @@ const apiGetAdminVotingByStatus = async ({
}
};
const apiGetAdminVotingRiwayat = async ({
page,
search,
@@ -133,3 +134,68 @@ const apiGetAdminVotingRiwayat = async ({
}
};
const apiGetOneAdminVotingById = async ({ id }: { id: string }) => {
try {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) {
console.error("No token found");
return null;
}
const response = await fetch(`/api/admin/vote/${id}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Error get one data voting admin",
errorData?.message || "Unknown error"
);
return null;
}
return response.json();
} catch (error) {
console.log("Error get one data voting admin", error);
throw error;
}
};
const apiGetAdminKontibutorVotingById = async ({ id }: { id: string }) => {
try {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) {
console.error("No token found");
return null;
}
const response = await fetch(`/api/admin/vote/${id}/kontributor`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error(
"Error get one data voting admin",
errorData?.message || "Unknown error"
);
return null;
}
return response.json();
} catch (error) {
console.log("Error get one data voting admin", error);
throw error;
}
};