web-humas-fe/services/magazine.tsx

72 lines
2.0 KiB
TypeScript
Raw Normal View History

2025-01-21 07:31:30 +00:00
import { PaginationRequest } from "@/types/globals";
2025-05-28 06:56:41 +00:00
import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
import Cookies from "js-cookie";
2025-05-28 06:56:41 +00:00
import { httpDeleteInterceptor } from "./http-config/http-interceptor-services";
const token = Cookies.get("access_token");
export async function createMagazine(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/magazines`;
return await httpPost(pathUrl, headers, data);
}
2025-01-21 07:31:30 +00:00
export async function getListMagazine(props: PaginationRequest) {
2025-05-28 06:56:41 +00:00
const { page, limit, search, startDate, endDate, timeStamp } = props;
2025-01-21 07:31:30 +00:00
const headers = {
"content-type": "application/json",
};
return await httpGet(
`/magazines?limit=${limit}&page=${page}&title=${search}&startDate=${
startDate || ""
2025-05-28 06:56:41 +00:00
}&endDate=${endDate || ""}&timeStamp=${timeStamp || ""}`,
2025-01-21 07:31:30 +00:00
headers
);
}
2025-01-21 08:46:31 +00:00
export async function updateMagazine(id: string, data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/magazines/${id}`;
return await httpPut(pathUrl, headers, data);
}
export async function getMagazineById(id: string) {
const headers = {
"content-type": "application/json",
};
return await httpGet(`/magazines/${id}`, headers);
}
export async function deleteMagazine(id: string) {
2025-03-18 08:30:18 +00:00
const headers = {
"content-type": "application/json",
};
2025-05-28 06:56:41 +00:00
return await httpDeleteInterceptor(`magazines/${id}`);
2025-01-21 08:46:31 +00:00
}
export async function uploadMagazineFile(id: string, data: any) {
const headers = {
"content-type": "multipart/form-data",
};
return await httpPost(`/magazine-files/${id}`, headers, data);
}
2025-01-21 11:20:58 +00:00
export async function uploadMagazineThumbnail(id: string, data: any) {
const headers = {
"content-type": "multipart/form-data",
};
return await httpPost(`/magazines/thumbnail/${id}`, headers, data);
}
2025-01-21 11:20:58 +00:00
export async function deleteMagazineFiles(id: number) {
2025-03-18 08:30:18 +00:00
const headers = {
"content-type": "multipart/form-data",
};
2025-05-28 06:56:41 +00:00
return await httpDeleteInterceptor(`magazine-files/${id}`);
2025-01-21 11:20:58 +00:00
}