diff --git a/components/main/dashboard/dashboard-container.tsx b/components/main/dashboard/dashboard-container.tsx index be68314..d4e9e2a 100644 --- a/components/main/dashboard/dashboard-container.tsx +++ b/components/main/dashboard/dashboard-container.tsx @@ -30,6 +30,7 @@ import Link from "next/link"; import { useEffect, useState } from "react"; import { getListArticle, + getListArticleAdminPage, getStatisticSummary, getTopArticles, getUserLevelDataStat, @@ -108,7 +109,7 @@ export default function DashboardContainer() { page: page, search: "", }; - const res = await getListArticle(req); + const res = await getListArticleAdminPage(req); setArticle(res.data?.data); setTotalPage(res?.data?.meta?.totalPage); } diff --git a/components/table/article-table.tsx b/components/table/article-table.tsx index e55cec3..8838c6d 100644 --- a/components/table/article-table.tsx +++ b/components/table/article-table.tsx @@ -14,6 +14,7 @@ import { deleteArticle, getArticleByCategory, getListArticle, + getListArticleAdminPage, updateIsBannerArticle, } from "@/services/article"; import { Article } from "@/types/globals"; @@ -209,7 +210,7 @@ export default function ArticleTable() { sort: "desc", sortBy: "created_at", }; - const res = await getListArticle(req); + const res = await getListArticleAdminPage(req); await getTableNumber(parseInt(showData), res.data?.data); setTotalPage(res?.data?.meta?.totalPage); close(); diff --git a/services/article.ts b/services/article.ts index 5b069fc..0da8027 100644 --- a/services/article.ts +++ b/services/article.ts @@ -43,11 +43,46 @@ export async function getListArticle(props: PaginationRequest) { ); } +export async function getListArticleAdminPage(props: PaginationRequest) { + const { + page, + limit, + search, + startDate, + endDate, + isPublish, + category, + sortBy, + sort, + categorySlug, + isBanner, + categoryIds, + createdByIds, + } = props; + const headers = { + "content-type": "application/json", + Authorization: `Bearer ${token}`, + }; + return await httpGet( + `/articles?sort=desc&sortBy=created_at&limit=${limit}&page=${page}&isPublish=${ + isPublish === undefined ? "" : isPublish + }&title=${search}&startDate=${startDate || ""}&endDate=${ + endDate || "" + }&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${ + sort || "asc" + }&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${ + categoryIds || "" + }&createdByIds=${createdByIds || ""}`, + headers + ); +} + export async function getTopArticles(props: PaginationRequest) { const { page, limit, search, startDate, endDate, isPublish, category } = props; const headers = { "content-type": "application/json", + Authorization: `Bearer ${token}`, }; return await httpGet( `/articles?sort=desc&sortBy=created_at&limit=${limit}&page=${page}&isPublish=${