import { PaginationRequest } from "@/types/globals"; import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service"; import Cookies from "js-cookie"; import { stat } from "fs"; import { httpGetInterceptor, httpPostInterceptor, } from "./http-config/http-interceptor-services"; const token = Cookies.get("access_token"); export async function getListArticle(props: PaginationRequest) { const { page, limit, search, startDate, endDate, isPublish, category, sortBy, sort, categorySlug, isBanner, categoryIds, createdByIds, isPolda, } = props; const headers = { "content-type": "application/json", }; return await httpGet( `/articles/public?limit=${limit}&page=${page}&isPublish=${ isPublish === undefined ? "" : isPublish }&title=${search}&startDate=${startDate || ""}&endDate=${ endDate || "" }&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${ sort || "desc" }&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${ categoryIds || "" }&createdByIds=${createdByIds || ""}&isPolda=${isPolda || ""}`, headers ); } export async function getListArticleAdminPage(props: PaginationRequest) { const { page, limit, search, startDate, endDate, isPublish, category, sortBy, sort, categorySlug, isBanner, categoryIds, createdByIds, timeStamp, } = props; return await httpGetInterceptor( `/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 || ""}&timeStamp=${timeStamp || ""}` ); } export async function getTopArticles(props: PaginationRequest) { const { page, limit, search, startDate, endDate, isPublish, category, timeStamp, } = props; return await httpGetInterceptor( `/articles?limit=${limit}&page=${page}&isPublish=${ isPublish === undefined ? "" : isPublish }&title=${search}&startDate=${startDate || ""}&endDate=${ endDate || "" }&category=${category || ""}&sortBy=view_count&sort=desc&timeStamp=${ timeStamp || "" }` ); } export async function createArticle(data: any) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; const pathUrl = `/articles`; return await httpPost(pathUrl, headers, data); } export async function createArticleSchedule(data: any) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; const pathUrl = `/articles/publish-scheduling?id=${data.id}&date=${data.date}`; return await httpPost(pathUrl, headers, data); } export async function updateArticle(id: string, data: any) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; const pathUrl = `/articles/${id}`; return await httpPut(pathUrl, headers, data); } export async function getArticleById(id: any) { const headers = { "content-type": "application/json", }; return await httpGet(`/articles/${id}`, headers); } export async function getRecapArticleData(data: any) { const headers = { "content-type": "application/json", }; return await httpGet( `/articles?page=${data.page}&userLevelId=${data.id}&startDate=${data.startDate}&endDate=${data.endDate}&startTime=${data.startTime}&endTime=${data.endTime}`, headers ); } // export async function deleteArticle(id: string) { // const headers = { // "content-type": "application/json", // }; // return await httpDeleteInterceptor(`articles/${id}`, headers); // } export async function deleteArticle(id: string) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpPut(`articles/delete/${id}`, headers); } export async function getArticleByCategory(timeStamp: number) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGetInterceptor( `/article-categories?limit=1000&timeStamp=${timeStamp}` ); } export async function getCategoryPagination(data: any) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGetInterceptor( `/article-categories?limit=${data?.limit}&page=${data?.page}&title=${data?.search}&timeStamp=${data.timeStamp}` ); } export async function uploadArticleFile(id: string, data: any) { const headers = { "content-type": "multipart/form-data", Authorization: `Bearer ${token}`, }; return await httpPost(`/article-files/${id}`, headers, data); } export async function uploadArticleThumbnail(id: string, data: any) { const headers = { "content-type": "multipart/form-data", Authorization: `Bearer ${token}`, }; return await httpPost(`/articles/thumbnail/${id}`, headers, data); } // export async function deleteArticleFiles(id: number) { // const headers = { // "content-type": "multipart/form-data", // }; // return await httpDeleteInterceptor(`article-files/${id}`, headers); // } export async function deleteArticleFiles(id: number) { const headers = { "content-type": "multipart/form-data", Authorization: `Bearer ${token}`, }; return await httpPut(`article-files/delete/${id}`, headers); } export async function getUserLevelDataStat( startDate: string, endDate: string, timeStamp: number, startTime: string, endTime: string, levelType: string, levelId?: number ) { // const headers = { // "content-type": "application/json", // Authorization: `Bearer ${token}`, // }; return await httpGetInterceptor( `/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&startTime=${startTime}&endTime=${endTime}&levelType=${levelType}&userLevelId=${ levelId || "" }&timeStamp=${timeStamp}` ); } export async function getStatisticForMaps(startDate: string, endDate: string) { const headers = { "content-type": "application/json", // Authorization: `Bearer ${token}`, }; return await httpGet( `/activity-logs/visitors-by-region-stats?startDate=${startDate}&endDate=${endDate}`, headers ); } export async function getStatisticVisitorsBrowser( startDate: string, endDate: string ) { const headers = { "content-type": "application/json", // Authorization: `Bearer ${token}`, }; return await httpGet( `/activity-logs/visitors-by-browser-stats?startDate=${startDate}&endDate=${endDate}`, headers ); } export async function getStatisticMonthly(year: string, timeStamp: number) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGetInterceptor( `/articles/statistic/monthly?year=${year}&timeStamp=${timeStamp}` ); } export async function getStatisticVisitorsMonthly(year: string) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGet( `/activity-logs/visitors-monthly-stats?year=${year}`, headers ); } export async function getStatisticUsersMonthly(year: string) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGet( `/articles/statistic/monthly-per-user-level?year=${year}`, headers ); } export async function getStatisticMonthlyFeedback( year: string, timeStamp: number ) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGet( `/feedbacks/statistic/monthly?year=${year}&timeStamp=${timeStamp}`, headers ); } export async function getStatisticSummary(timeStamp: number) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; return await httpGetInterceptor( `/articles/statistic/summary?timeStamp=${timeStamp}` ); } export async function submitApproval(data: { articleId: number; message: string; statusId: number; }) { const headers = { "content-type": "multipart/form-data", Authorization: `Bearer ${token}`, }; return await httpPost(`/article-approvals`, headers, data); } export async function updateIsBannerArticle(id: number, status: boolean) { const headers = { "content-type": "application/json", Authorization: `Bearer ${token}`, }; const pathUrl = `/articles/banner/${id}?isBanner=${status}`; return await httpPut(pathUrl, headers); } export async function getArticleByCategoryLanding(props: { limit: string; title: string; }) { const headers = { "content-type": "application/json", }; return await httpGet( `/article-categories?limit=${props.limit}&title=${props.title}`, headers ); }