web-humas-fe/services/advertisement.ts

92 lines
2.7 KiB
TypeScript

import { httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
import Cookies from "js-cookie";
import {
httpDeleteInterceptor,
httpGetInterceptor,
} from "./http-config/http-interceptor-services";
const token = Cookies.get("access_token");
export async function createAdvertise(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/advertisement`;
return await httpPost(pathUrl, headers, data);
}
export async function createMediaFileAdvertise(id: string | number, data: any) {
const headers = {
"content-type": "multipart/form-data",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/advertisement/upload/${id}`;
return await httpPost(pathUrl, headers, data);
}
export async function getAdvertise(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/advertisement?page=${data?.page || 1}&limit=${
data?.limit || ""
}&placement=${data?.placement || ""}&isPublish=${
data.isPublish || ""
}&timeStamp=${data.timeStamp || ""}`;
return await httpGet(pathUrl, headers);
}
export async function getAdvertiseAdmin(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/advertisement?page=${data?.page || 1}&limit=${
data?.limit || ""
}&placement=${data?.placement || ""}&isPublish=${
data.isPublish || ""
}&timeStamp=${data.timeStamp || ""}`;
return await httpGetInterceptor(pathUrl);
}
export async function createAdvertiseById(id: number) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/advertisement/${id}`;
return await httpGet(pathUrl, headers);
}
export async function editAdvertise(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/advertisement/${data?.id}`;
return await httpPut(pathUrl, headers, data);
}
export async function editAdvertiseIsActive(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/advertisement/publish/${data?.id}?isPublish=${data?.isActive}`;
return await httpPut(pathUrl, headers);
}
// export async function deleteAdvertise(id: number) {
// const headers = {
// "content-type": "application/json",
// };
// const pathUrl = `/advertisement/${id}`;
// return await httpDeleteInterceptor(pathUrl, headers);
// }
export async function deleteAdvertise(id: number) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
const pathUrl = `/advertisement/delete/${id}`;
return await httpPut(pathUrl, headers);
}