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";
|
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) {
|
2024-11-13 08:29:27 +00:00
|
|
|
const { page, limit, search, startDate, endDate } = props;
|
2024-11-08 09:01:21 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
return await httpGet(
|
2024-11-13 08:29:27 +00:00
|
|
|
`/articles?limit=${limit}&page=${page}&title=${search}&startDate=${startDate}&endDate=${endDate}`,
|
2024-11-08 09:01:21 +00:00
|
|
|
headers
|
|
|
|
|
);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function updateArticle(id: any) {
|
2024-11-08 09:01:21 +00:00
|
|
|
const headers = {
|
|
|
|
|
"content-type": "application/json",
|
|
|
|
|
};
|
|
|
|
|
const pathUrl = `/articles/${id}`;
|
|
|
|
|
return await httpPut(pathUrl, headers);
|
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) {
|
2024-11-08 09:01:21 +00:00
|
|
|
return await httpDeleteInterceptor(`articles/${id}`);
|
|
|
|
|
}
|