2024-11-08 09:01:21 +00:00
|
|
|
import { PaginationRequest } from "@/types/globals";
|
|
|
|
|
import {
|
|
|
|
|
httpDeleteInterceptor,
|
|
|
|
|
httpGet,
|
|
|
|
|
httpPost,
|
|
|
|
|
httpPut,
|
|
|
|
|
} from "./http-config/axios-base-service";
|
2024-11-22 10:59:58 +00:00
|
|
|
import Cookies from "js-cookie";
|
2025-04-07 07:17:35 +00:00
|
|
|
import { stat } from "fs";
|
2025-05-19 03:33:49 +00:00
|
|
|
import axiosInterceptorInstanceHumas from "./http-config/konten-humas-base-service";
|
2025-05-25 10:21:54 +00:00
|
|
|
import { httpGetInterceptor } from "./http-config/http-interceptor-services";
|
2024-04-04 10:30:07 +00:00
|
|
|
|
2024-11-22 10:59:58 +00:00
|
|
|
const token = Cookies.get("access_token");
|
2024-11-08 09:01:21 +00:00
|
|
|
export async function getListArticle(props: PaginationRequest) {
|
2025-02-17 10:01:58 +00:00
|
|
|
const {
|
|
|
|
|
page,
|
|
|
|
|
limit,
|
|
|
|
|
search,
|
|
|
|
|
startDate,
|
|
|
|
|
endDate,
|
|
|
|
|
isPublish,
|
|
|
|
|
category,
|
|
|
|
|
sortBy,
|
|
|
|
|
sort,
|
2025-03-18 08:30:18 +00:00
|
|
|
categorySlug,
|
2025-04-07 07:17:35 +00:00
|
|
|
isBanner,
|
2025-05-24 04:59:31 +00:00
|
|
|
categoryIds,
|
|
|
|
|
createdByIds,
|
2025-02-17 10:01:58 +00:00
|
|
|
} = props;
|
2024-11-08 09:01:21 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
return await httpGet(
|
2025-05-25 18:12:17 +00:00
|
|
|
`/articles/public?sort=desc&sortBy=created_at&limit=${limit}&page=${page}&isPublish=${
|
2025-02-10 09:16:52 +00:00
|
|
|
isPublish === undefined ? "" : isPublish
|
2025-02-14 16:11:51 +00:00
|
|
|
}&title=${search}&startDate=${startDate || ""}&endDate=${
|
|
|
|
|
endDate || ""
|
2025-03-17 15:45:12 +00:00
|
|
|
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
2025-02-17 10:01:58 +00:00
|
|
|
sort || "asc"
|
2025-05-24 04:59:31 +00:00
|
|
|
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${
|
|
|
|
|
categoryIds || ""
|
|
|
|
|
}&createdByIds=${createdByIds || ""}`,
|
2024-11-08 09:01:21 +00:00
|
|
|
headers
|
|
|
|
|
);
|
2024-04-19 13:26:27 +00:00
|
|
|
}
|
|
|
|
|
|
2025-05-25 09:20:56 +00:00
|
|
|
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}`,
|
|
|
|
|
};
|
2025-05-25 10:21:54 +00:00
|
|
|
return await httpGetInterceptor(
|
2025-05-25 09:20:56 +00:00
|
|
|
`/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 || ""
|
2025-05-25 10:21:54 +00:00
|
|
|
}&createdByIds=${createdByIds || ""}`
|
2025-05-25 09:20:56 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-17 07:21:28 +00:00
|
|
|
export async function getTopArticles(props: PaginationRequest) {
|
|
|
|
|
const { page, limit, search, startDate, endDate, isPublish, category } =
|
|
|
|
|
props;
|
2025-05-25 18:12:17 +00:00
|
|
|
return await httpGetInterceptor(
|
2025-05-24 16:49:31 +00:00
|
|
|
`/articles?sort=desc&sortBy=created_at&limit=${limit}&page=${page}&isPublish=${
|
2025-02-17 07:21:28 +00:00
|
|
|
isPublish === undefined ? "" : isPublish
|
|
|
|
|
}&title=${search}&startDate=${startDate || ""}&endDate=${
|
|
|
|
|
endDate || ""
|
2025-05-25 18:12:17 +00:00
|
|
|
}&category=${category || ""}&sortBy=view_count&sort=desc`
|
2025-02-17 07:21:28 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-19 13:26:27 +00:00
|
|
|
export async function createArticle(data: any) {
|
2024-11-08 09:01:21 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
2024-11-22 10:59:58 +00:00
|
|
|
Authorization: `Bearer ${token}`,
|
2024-11-08 09:01:21 +00:00
|
|
|
};
|
|
|
|
|
const pathUrl = `/articles`;
|
|
|
|
|
return await httpPost(pathUrl, headers, data);
|
2024-04-24 04:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
2025-02-27 11:09:32 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-17 10:23:54 +00:00
|
|
|
export async function updateArticle(id: string, data: any) {
|
2024-11-08 09:01:21 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
const pathUrl = `/articles/${id}`;
|
2025-01-17 10:23:54 +00:00
|
|
|
return await httpPut(pathUrl, headers, data);
|
2024-04-24 04:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getArticleById(id: any) {
|
2024-11-08 09:01:21 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
return await httpGet(`/articles/${id}`, headers);
|
2024-04-24 04:14:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteArticle(id: string) {
|
2025-03-18 08:30:18 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
return await httpDeleteInterceptor(`articles/${id}`, headers);
|
2024-11-08 09:01:21 +00:00
|
|
|
}
|
2024-11-26 03:55:40 +00:00
|
|
|
|
|
|
|
|
export async function getArticleByCategory() {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
2025-02-17 07:21:28 +00:00
|
|
|
Authorization: `Bearer ${token}`,
|
2024-11-26 03:55:40 +00:00
|
|
|
};
|
2025-03-17 15:45:12 +00:00
|
|
|
return await httpGet(`/article-categories?limit=1000`, headers);
|
2024-11-26 03:55:40 +00:00
|
|
|
}
|
2025-01-19 16:13:06 +00:00
|
|
|
export async function getCategoryPagination(data: any) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
2025-02-17 07:21:28 +00:00
|
|
|
Authorization: `Bearer ${token}`,
|
2025-01-19 16:13:06 +00:00
|
|
|
};
|
2025-02-17 07:21:28 +00:00
|
|
|
|
2025-05-25 15:17:10 +00:00
|
|
|
return await httpGetInterceptor(
|
|
|
|
|
`/article-categories?limit=${data?.limit}&page=${data?.page}&title=${data?.search}`
|
2025-01-19 16:13:06 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function uploadArticleFile(id: string, data: any) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "multipart/form-data",
|
|
|
|
|
};
|
|
|
|
|
return await httpPost(`/article-files/${id}`, headers, data);
|
|
|
|
|
}
|
|
|
|
|
export async function uploadArticleThumbnail(id: string, data: any) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "multipart/form-data",
|
|
|
|
|
};
|
|
|
|
|
return await httpPost(`/articles/thumbnail/${id}`, headers, data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function deleteArticleFiles(id: number) {
|
2025-03-18 08:30:18 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "multipart/form-data",
|
|
|
|
|
};
|
|
|
|
|
return await httpDeleteInterceptor(`article-files/${id}`, headers);
|
2025-01-19 16:13:06 +00:00
|
|
|
}
|
2025-02-17 07:21:28 +00:00
|
|
|
|
|
|
|
|
export async function getUserLevelDataStat(startDate: string, endDate: string) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
};
|
|
|
|
|
return await httpGet(
|
|
|
|
|
`/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}`,
|
|
|
|
|
headers
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
export async function getStatisticMonthly(year: string) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
};
|
|
|
|
|
return await httpGet(`/articles/statistic/monthly?year=${year}`, headers);
|
|
|
|
|
}
|
2025-04-07 07:17:35 +00:00
|
|
|
export async function getStatisticMonthlyFeedback(year: string) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
};
|
|
|
|
|
return await httpGet(`/feedbacks/statistic/monthly?year=${year}`, headers);
|
|
|
|
|
}
|
2025-02-17 07:21:28 +00:00
|
|
|
export async function getStatisticSummary() {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
};
|
2025-05-25 15:17:10 +00:00
|
|
|
return await httpGetInterceptor(`/articles/statistic/summary`);
|
2025-02-17 07:21:28 +00:00
|
|
|
}
|
2025-02-17 16:32:20 +00:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2025-04-07 07:17:35 +00:00
|
|
|
|
|
|
|
|
export async function updateIsBannerArticle(id: number, status: boolean) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
const pathUrl = `/articles/banner/${id}?isBanner=${status}`;
|
|
|
|
|
return await httpPut(pathUrl, headers);
|
|
|
|
|
}
|
2025-05-19 03:33:49 +00:00
|
|
|
|
|
|
|
|
export async function httpGetHumas(pathUrl: any, headers: any) {
|
|
|
|
|
const response = await axiosInterceptorInstanceHumas
|
|
|
|
|
.get(pathUrl, { headers })
|
|
|
|
|
.catch(function (error: any) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
return error.response;
|
|
|
|
|
});
|
|
|
|
|
console.log("Response base svc : ", response);
|
|
|
|
|
if (response?.status == 200 || response?.status == 201) {
|
|
|
|
|
return {
|
|
|
|
|
error: false,
|
|
|
|
|
message: "success",
|
|
|
|
|
data: response?.data,
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
error: true,
|
|
|
|
|
message: response?.data?.message || response?.data || null,
|
|
|
|
|
data: null,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getArticleByIdHumas(id: any) {
|
|
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
return await httpGetHumas(`/articles/${id}`, headers);
|
|
|
|
|
}
|