163 lines
4.3 KiB
TypeScript
163 lines
4.3 KiB
TypeScript
import { PaginationRequest } from "@/types/globals";
|
|
import {
|
|
httpDeleteInterceptor,
|
|
httpGet,
|
|
httpPost,
|
|
httpPut,
|
|
} from "./http-config/axios-base-service";
|
|
import Cookies from "js-cookie";
|
|
|
|
const token = Cookies.get("access_token");
|
|
export async function getListArticle(props: PaginationRequest) {
|
|
const {
|
|
page,
|
|
limit,
|
|
search,
|
|
startDate,
|
|
endDate,
|
|
isPublish,
|
|
category,
|
|
sortBy,
|
|
sort,
|
|
} = props;
|
|
const headers = {
|
|
"content-type": "application/json",
|
|
};
|
|
return await httpGet(
|
|
`/articles?limit=${limit}&page=${page}&isPublish=${
|
|
isPublish === undefined ? "" : isPublish
|
|
}&title=${search}&startDate=${startDate || ""}&endDate=${
|
|
endDate || ""
|
|
}&category=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
|
sort || "asc"
|
|
}`,
|
|
headers
|
|
);
|
|
}
|
|
|
|
export async function getTopArticles(props: PaginationRequest) {
|
|
const { page, limit, search, startDate, endDate, isPublish, category } =
|
|
props;
|
|
const headers = {
|
|
"content-type": "application/json",
|
|
};
|
|
return await httpGet(
|
|
`/articles?limit=${limit}&page=${page}&isPublish=${
|
|
isPublish === undefined ? "" : isPublish
|
|
}&title=${search}&startDate=${startDate || ""}&endDate=${
|
|
endDate || ""
|
|
}&category=${category || ""}&sortBy=view_count&sort=desc`,
|
|
headers
|
|
);
|
|
}
|
|
|
|
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",
|
|
};
|
|
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 deleteArticle(id: string) {
|
|
return await httpDeleteInterceptor(`articles/${id}`);
|
|
}
|
|
|
|
export async function getArticleByCategory() {
|
|
const headers = {
|
|
"content-type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
return await httpGet(`/article-categories?limit=200`, headers);
|
|
}
|
|
export async function getCategoryPagination(data: any) {
|
|
const headers = {
|
|
"content-type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
|
|
return await httpGet(
|
|
`/article-categories?limit=${data?.limit}&page=${data?.page}&title=${data?.search}`,
|
|
headers
|
|
);
|
|
}
|
|
|
|
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) {
|
|
return await httpDeleteInterceptor(`article-files/${id}`);
|
|
}
|
|
|
|
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);
|
|
}
|
|
export async function getStatisticSummary() {
|
|
const headers = {
|
|
"content-type": "application/json",
|
|
Authorization: `Bearer ${token}`,
|
|
};
|
|
return await httpGet(`/articles/statistic/summary`, headers);
|
|
}
|
|
|
|
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);
|
|
}
|