web-humas-fe/services/article.ts

323 lines
8.8 KiB
TypeScript
Raw Normal View History

import { PaginationRequest } from "@/types/globals";
2025-05-26 06:07:26 +00:00
import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
import Cookies from "js-cookie";
import { stat } from "fs";
2025-05-26 06:07:26 +00:00
import {
httpGetInterceptor,
httpPostInterceptor,
2025-05-26 06:07:26 +00:00
} from "./http-config/http-interceptor-services";
2024-04-04 10:30:07 +00:00
const token = Cookies.get("access_token");
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,
isBanner,
categoryIds,
createdByIds,
2025-05-31 19:00:00 +00:00
isPolda,
2026-01-22 04:05:51 +00:00
timeStamp,
2025-02-17 10:01:58 +00:00
} = props;
const headers = {
"content-type": "application/json",
};
return await httpGet(
2025-05-31 19:00:00 +00:00
`/articles/public?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=${
sort || "desc"
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}&categoryIds=${
categoryIds || ""
2026-02-03 15:34:40 +00:00
}&createdByIds=${createdByIds || ""}&isPolda=${isPolda || ""}`,
2026-01-19 06:03:54 +00:00
headers,
);
2024-04-19 13:26:27 +00:00
}
2026-01-29 12:00:18 +00:00
export async function getListArticleAdminPage(props: any) {
2025-05-25 09:20:56 +00:00
const {
page,
limit,
search,
startDate,
endDate,
isPublish,
category,
sortBy,
sort,
categorySlug,
isBanner,
categoryIds,
createdByIds,
2025-05-28 06:56:41 +00:00
timeStamp,
2025-05-25 09:20:56 +00:00
} = props;
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 || ""
2026-02-27 02:04:05 +00:00
}&createdByIds=${createdByIds || ""}${timeStamp ? `timeStamp=${timeStamp}` : ""}`,
2025-05-25 09:20:56 +00:00
);
}
2025-02-17 07:21:28 +00:00
export async function getTopArticles(props: PaginationRequest) {
2025-05-28 06:56:41 +00:00
const {
page,
limit,
search,
startDate,
endDate,
isPublish,
category,
timeStamp,
} = props;
return await httpGetInterceptor(
2025-02-17 07:21:28 +00:00
`/articles?limit=${limit}&page=${page}&isPublish=${
isPublish === undefined ? "" : isPublish
}&title=${search}&startDate=${startDate || ""}&endDate=${
endDate || ""
2026-02-03 15:34:40 +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) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/articles`;
return await httpPost(pathUrl, headers, data);
2024-04-24 04:14:06 +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) {
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
};
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
}
2026-02-27 02:11:52 +00:00
export async function getArticleById(id: any, timeStamp?: any) {
const headers = {
"content-type": "application/json",
};
2026-02-27 02:05:55 +00:00
return await httpGet(`/articles/${id}?timeStamp=${timeStamp}`, headers);
2024-04-24 04:14:06 +00:00
}
2025-06-18 02:32:56 +00:00
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}`,
2026-01-19 06:03:54 +00:00
headers,
2025-06-18 02:32:56 +00:00
);
}
2024-04-24 04:14:06 +00:00
2025-06-11 09:38:29 +00:00
// export async function deleteArticle(id: string) {
// const headers = {
// "content-type": "application/json",
// };
// return await httpDeleteInterceptor(`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",
2025-05-26 06:07:26 +00:00
Authorization: `Bearer ${token}`,
2025-03-18 08:30:18 +00:00
};
2025-06-11 09:38:29 +00:00
return await httpPut(`articles/delete/${id}`, headers);
}
2024-11-26 03:55:40 +00:00
2025-05-28 06:56:41 +00:00
export async function getArticleByCategory(timeStamp: number) {
2024-11-26 03:55:40 +00:00
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
};
2026-02-03 15:34:40 +00:00
return await httpGetInterceptor(`/article-categories?limit=1000`);
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
return await httpGetInterceptor(
2026-02-03 15:34:40 +00:00
`/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",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
2025-01-19 16:13:06 +00:00
};
return await httpPost(`/article-files/${id}`, headers, data);
}
export async function uploadArticleThumbnail(id: string, data: any) {
const headers = {
"content-type": "multipart/form-data",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
2025-01-19 16:13:06 +00:00
};
return await httpPost(`/articles/thumbnail/${id}`, headers, data);
}
2025-06-11 09:38:29 +00:00
// export async function deleteArticleFiles(id: number) {
// const headers = {
// "content-type": "multipart/form-data",
// };
// return await httpDeleteInterceptor(`article-files/${id}`, headers);
// }
2025-01-19 16:13:06 +00:00
export async function deleteArticleFiles(id: number) {
2025-03-18 08:30:18 +00:00
const headers = {
"content-type": "multipart/form-data",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
2025-03-18 08:30:18 +00:00
};
2025-06-11 09:38:29 +00:00
return await httpPut(`article-files/delete/${id}`, headers);
2025-01-19 16:13:06 +00:00
}
2025-02-17 07:21:28 +00:00
2025-05-28 06:56:41 +00:00
export async function getUserLevelDataStat(
startDate: string,
endDate: string,
2025-06-13 10:35:07 +00:00
timeStamp: number,
startTime: string,
endTime: string,
2025-06-17 16:55:17 +00:00
levelType: string,
2026-01-19 06:03:54 +00:00
levelId?: number,
2025-05-28 06:56:41 +00:00
) {
// const headers = {
// "content-type": "application/json",
// Authorization: `Bearer ${token}`,
// };
2025-05-28 06:56:41 +00:00
return await httpGetInterceptor(
2025-06-17 16:55:17 +00:00
`/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}&startTime=${startTime}&endTime=${endTime}&levelType=${levelType}&userLevelId=${
levelId || ""
2026-02-03 15:34:40 +00:00
}`,
2025-02-17 07:21:28 +00:00
);
}
2025-06-28 05:14:54 +00:00
export async function getStatisticForMaps(startDate: string, endDate: string) {
const headers = {
"content-type": "application/json",
2026-02-06 08:13:35 +00:00
Authorization: `Bearer ${token}`,
2025-06-28 05:14:54 +00:00
};
return await httpGet(
2025-06-28 16:39:22 +00:00
`/activity-logs/visitors-by-region-stats?startDate=${startDate}&endDate=${endDate}`,
2026-01-19 06:03:54 +00:00
headers,
2025-06-28 05:14:54 +00:00
);
}
export async function getStatisticVisitorsBrowser(
startDate: string,
2026-01-19 06:03:54 +00:00
endDate: string,
) {
const headers = {
"content-type": "application/json",
2026-02-06 08:13:35 +00:00
Authorization: `Bearer ${token}`,
};
return await httpGet(
`/activity-logs/visitors-by-browser-stats?startDate=${startDate}&endDate=${endDate}`,
2026-01-19 06:03:54 +00:00
headers,
);
}
2025-05-28 06:56:41 +00:00
export async function getStatisticMonthly(year: string, timeStamp: number) {
2025-02-17 07:21:28 +00:00
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
2026-02-03 15:34:40 +00:00
return await httpGetInterceptor(`/articles/statistic/monthly?year=${year}`);
2025-02-17 07:21:28 +00:00
}
2025-06-29 05:57:23 +00:00
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}`,
2026-01-19 06:03:54 +00:00
headers,
2025-06-29 05:57:23 +00:00
);
}
2025-06-28 05:14:54 +00:00
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}`,
2026-01-19 06:03:54 +00:00
headers,
2025-06-28 05:14:54 +00:00
);
}
2025-05-28 06:56:41 +00:00
export async function getStatisticMonthlyFeedback(
year: string,
2026-01-19 06:03:54 +00:00
timeStamp: number,
2025-05-28 06:56:41 +00:00
) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
2026-02-03 15:34:40 +00:00
return await httpGet(`/feedbacks/statistic/monthly?year=${year}`, headers);
}
2025-05-28 06:56:41 +00:00
export async function getStatisticSummary(timeStamp: number) {
2025-02-17 07:21:28 +00:00
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
2026-02-03 15:34:40 +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);
}
export async function updateIsBannerArticle(id: number, status: boolean) {
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
};
const pathUrl = `/articles/banner/${id}?isBanner=${status}`;
return await httpPut(pathUrl, headers);
}
2025-05-19 03:33:49 +00:00
export async function getArticleByCategoryLanding(props: {
limit: string;
title: string;
2026-01-19 06:03:54 +00:00
timeStamp?: number;
}) {
2025-05-19 03:33:49 +00:00
const headers = {
"content-type": "application/json",
};
return await httpGet(
2026-02-03 15:34:40 +00:00
`/article-categories?limit=${props.limit}&title=${props.title}`,
2026-01-19 06:03:54 +00:00
headers,
);
2025-05-19 03:33:49 +00:00
}