web-humas-fe/service/article.ts

84 lines
2.2 KiB
TypeScript
Raw Normal View History

import { PaginationRequest } from "@/types/globals";
import {
httpDeleteInterceptor,
httpGet,
httpPost,
httpPut,
} from "./http-config/axios-base-service";
import Cookies from "js-cookie";
2024-04-04 10:30:07 +00:00
const token = Cookies.get("access_token");
export async function getListArticle(props: PaginationRequest) {
const { page, limit, search, startDate, endDate } = props;
const headers = {
"content-type": "application/json",
};
return await httpGet(
`/articles?limit=${limit}&page=${page}&title=${search}&startDate=${
startDate || ""
}&endDate=${endDate || ""}`,
headers
);
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
}
2025-01-17 10:23:54 +00:00
export async function updateArticle(id: string, data: any) {
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) {
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) {
return await httpDeleteInterceptor(`articles/${id}`);
}
2024-11-26 03:55:40 +00:00
export async function getArticleByCategory() {
const headers = {
"content-type": "application/json",
};
return await httpGet(`/article-categories?limit=50`, headers);
}
2025-01-19 16:13:06 +00:00
export async function getCategoryPagination(data: any) {
const headers = {
"content-type": "application/json",
};
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}`);
}