fix admin job

- fix table publish"
This commit is contained in:
2025-03-19 14:08:23 +08:00
parent fb6508db9b
commit f5d9242daa
10 changed files with 403 additions and 143 deletions

View File

@@ -1,67 +1,102 @@
export {
apiGetAdminJobStatusCountDashboard as apiGetJobStatusCountDashboard ,
apiGetAdminJobArsipCount as apiGetJobArsipCount,
apiGetAdminJobByStatus
}
apiGetAdminJobStatusCountDashboard as apiGetJobStatusCountDashboard,
apiGetAdminJobArsipCount as apiGetJobArsipCount,
apiGetAdminJobByStatus,
apiGetOneJobById,
};
const apiGetAdminJobStatusCountDashboard = async ({ name }: {
name: "Publish" | "Review" | "Reject";
const apiGetAdminJobStatusCountDashboard = 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 { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/job/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null)
}
const response = await fetch(`/api/admin/job/dashboard/${name}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
const apiGetAdminJobArsipCount = 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/job/dashboard/arsip`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
});
return await response.json().catch(() => null)
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/job/dashboard/arsip`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
const apiGetAdminJobByStatus = async ({
name,
page,
search
name,
page,
search,
}: {
name: "Publish" | "Review" | "Reject";
page: string;
search: string;
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 { 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/job/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)
}
const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : "";
const response = await fetch(
`/api/admin/job/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);
};
const apiGetOneJobById = async ({ id }: { id: string }) => {
try {
// Fetch token from cookie
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/job/${id}`, {
method: "GET",
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("Failed to get one job", response.statusText, errorData);
throw new Error(errorData?.message || "Failed to get one job");
}
// Return the JSON response
return await response.json();
} catch (error) {
console.error("Error get one job", error);
throw error; // Re-throw the error to handle it in the calling function
}
};