feat: update services all function
This commit is contained in:
parent
750eae2971
commit
de12444e17
|
|
@ -1,8 +1,11 @@
|
||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
env: {
|
||||||
|
MEDOLS_CLIENT_KEY: process.env.MEDOLS_CLIENT_KEY,
|
||||||
|
},
|
||||||
images: {
|
images: {
|
||||||
domains: ["kontenhumas.com"],
|
domains: ["mikulnews.com", "dev.mikulnews.com"],
|
||||||
},
|
},
|
||||||
eslint: {
|
eslint: {
|
||||||
ignoreDuringBuilds: true,
|
ignoreDuringBuilds: true,
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,8 @@
|
||||||
import { PaginationRequest } from "@/types/globals";
|
import { PaginationRequest } from "@/types/globals";
|
||||||
import {
|
|
||||||
httpDeleteInterceptor,
|
|
||||||
httpGet,
|
|
||||||
httpPost,
|
|
||||||
httpPut,
|
|
||||||
} from "./http-config/axios-base-service";
|
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
import { httpGet } from "./http-config/http-base-services";
|
||||||
|
import { httpDeleteInterceptor, httpPostInterceptor, httpPutInterceptor } from "./http-config/http-interceptor-services";
|
||||||
|
|
||||||
const token = Cookies.get("access_token");
|
|
||||||
export async function getListArticle(props: PaginationRequest) {
|
export async function getListArticle(props: PaginationRequest) {
|
||||||
const {
|
const {
|
||||||
page,
|
page,
|
||||||
|
|
@ -22,9 +17,6 @@ export async function getListArticle(props: PaginationRequest) {
|
||||||
categorySlug,
|
categorySlug,
|
||||||
isBanner,
|
isBanner,
|
||||||
} = props;
|
} = props;
|
||||||
const headers = {
|
|
||||||
"content-type": "application/json",
|
|
||||||
};
|
|
||||||
return await httpGet(
|
return await httpGet(
|
||||||
`/articles?limit=${limit}&page=${page}&isPublish=${
|
`/articles?limit=${limit}&page=${page}&isPublish=${
|
||||||
isPublish === undefined ? "" : isPublish
|
isPublish === undefined ? "" : isPublish
|
||||||
|
|
@ -33,7 +25,7 @@ export async function getListArticle(props: PaginationRequest) {
|
||||||
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
}&categoryId=${category || ""}&sortBy=${sortBy || "created_at"}&sort=${
|
||||||
sort || "asc"
|
sort || "asc"
|
||||||
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}`,
|
}&category=${categorySlug || ""}&isBanner=${isBanner || ""}`,
|
||||||
headers
|
null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,29 +46,18 @@ export async function getTopArticles(props: PaginationRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createArticle(data: any) {
|
export async function createArticle(data: any) {
|
||||||
const headers = {
|
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
const pathUrl = `/articles`;
|
const pathUrl = `/articles`;
|
||||||
return await httpPost(pathUrl, headers, data);
|
return await httpPostInterceptor(pathUrl, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createArticleSchedule(data: any) {
|
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}`;
|
const pathUrl = `/articles/publish-scheduling?id=${data.id}&date=${data.date}`;
|
||||||
return await httpPost(pathUrl, headers, data);
|
return await httpPostInterceptor(pathUrl, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateArticle(id: string, data: any) {
|
export async function updateArticle(id: string, data: any) {
|
||||||
const headers = {
|
|
||||||
"content-type": "application/json",
|
|
||||||
};
|
|
||||||
const pathUrl = `/articles/${id}`;
|
const pathUrl = `/articles/${id}`;
|
||||||
return await httpPut(pathUrl, headers, data);
|
return await httpPutInterceptor(pathUrl, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getArticleById(id: any) {
|
export async function getArticleById(id: any) {
|
||||||
|
|
@ -94,21 +75,11 @@ export async function deleteArticle(id: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getArticleByCategory() {
|
export async function getArticleByCategory() {
|
||||||
const headers = {
|
return await httpGet(`/article-categories?limit=1000`);
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
return await httpGet(`/article-categories?limit=1000`, headers);
|
|
||||||
}
|
}
|
||||||
export async function getCategoryPagination(data: any) {
|
export async function getCategoryPagination(data: any) {
|
||||||
const headers = {
|
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
|
|
||||||
return await httpGet(
|
return await httpGet(
|
||||||
`/article-categories?limit=${data?.limit}&page=${data?.page}&title=${data?.search}`,
|
`/article-categories?limit=${data?.limit}&page=${data?.page}&title=${data?.search}`
|
||||||
headers
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,13 +87,14 @@ export async function uploadArticleFile(id: string, data: any) {
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "multipart/form-data",
|
"content-type": "multipart/form-data",
|
||||||
};
|
};
|
||||||
return await httpPost(`/article-files/${id}`, headers, data);
|
return await httpPostInterceptor(`/article-files/${id}`, data, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function uploadArticleThumbnail(id: string, data: any) {
|
export async function uploadArticleThumbnail(id: string, data: any) {
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "multipart/form-data",
|
"content-type": "multipart/form-data",
|
||||||
};
|
};
|
||||||
return await httpPost(`/articles/thumbnail/${id}`, headers, data);
|
return await httpPostInterceptor(`/articles/thumbnail/${id}`, data, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteArticleFiles(id: number) {
|
export async function deleteArticleFiles(id: number) {
|
||||||
|
|
@ -133,35 +105,18 @@ export async function deleteArticleFiles(id: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getUserLevelDataStat(startDate: string, endDate: string) {
|
export async function getUserLevelDataStat(startDate: string, endDate: string) {
|
||||||
const headers = {
|
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
return await httpGet(
|
return await httpGet(
|
||||||
`/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}`,
|
`/articles/statistic/user-levels?startDate=${startDate}&endDate=${endDate}`
|
||||||
headers
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export async function getStatisticMonthly(year: string) {
|
export async function getStatisticMonthly(year: string) {
|
||||||
const headers = {
|
return await httpGet(`/articles/statistic/monthly?year=${year}`);
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
return await httpGet(`/articles/statistic/monthly?year=${year}`, headers);
|
|
||||||
}
|
}
|
||||||
export async function getStatisticMonthlyFeedback(year: string) {
|
export async function getStatisticMonthlyFeedback(year: string) {
|
||||||
const headers = {
|
return await httpGet(`/feedbacks/statistic/monthly?year=${year}`);
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
return await httpGet(`/feedbacks/statistic/monthly?year=${year}`, headers);
|
|
||||||
}
|
}
|
||||||
export async function getStatisticSummary() {
|
export async function getStatisticSummary() {
|
||||||
const headers = {
|
return await httpGet(`/articles/statistic/summary`);
|
||||||
"content-type": "application/json",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
return await httpGet(`/articles/statistic/summary`, headers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function submitApproval(data: {
|
export async function submitApproval(data: {
|
||||||
|
|
@ -169,11 +124,7 @@ export async function submitApproval(data: {
|
||||||
message: string;
|
message: string;
|
||||||
statusId: number;
|
statusId: number;
|
||||||
}) {
|
}) {
|
||||||
const headers = {
|
return await httpPostInterceptor(`/article-approvals`, data);
|
||||||
"content-type": "multipart/form-data",
|
|
||||||
Authorization: `Bearer ${token}`,
|
|
||||||
};
|
|
||||||
return await httpPost(`/article-approvals`, headers, data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateIsBannerArticle(id: number, status: boolean) {
|
export async function updateIsBannerArticle(id: number, status: boolean) {
|
||||||
|
|
@ -181,5 +132,5 @@ export async function updateIsBannerArticle(id: number, status: boolean) {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
};
|
};
|
||||||
const pathUrl = `/articles/banner/${id}?isBanner=${status}`;
|
const pathUrl = `/articles/banner/${id}?isBanner=${status}`;
|
||||||
return await httpPut(pathUrl, headers);
|
return await httpPutInterceptor(pathUrl, headers);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const baseURL = "http://38.47.180.165:8802";
|
const baseURL = "https://dev.mikulnews.com/api";
|
||||||
|
|
||||||
const axiosBaseInstance = axios.create({
|
const axiosBaseInstance = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
|
|
|
||||||
|
|
@ -4,42 +4,14 @@ import axiosBaseInstance from "./http-base-instance";
|
||||||
import mediahubBaseInstance from "./mediahub-base-service";
|
import mediahubBaseInstance from "./mediahub-base-service";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
function getCookie(name: string) {
|
const defaultHeaders = {
|
||||||
const value = `; ${document.cookie}`;
|
"Content-Type": "application/json",
|
||||||
console.log("val", value);
|
};
|
||||||
const parts: any = value.split(`; ${name}=`);
|
|
||||||
if (parts.length === 2) {
|
|
||||||
return parts.pop().split(";").shift();
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function removeCookies() {
|
|
||||||
console.log("run");
|
|
||||||
Cookies.remove("csrf_");
|
|
||||||
Cookies.remove("session_id");
|
|
||||||
|
|
||||||
document.cookie = "csrf_=; Max-Age=0;path=/";
|
|
||||||
document.cookie = "session_id=; Max-Age=0;path=/";
|
|
||||||
}
|
|
||||||
export async function httpPost(pathUrl: any, headers: any, data?: any) {
|
export async function httpPost(pathUrl: any, headers: any, data?: any) {
|
||||||
// const aCookie = getCookie("session_id");
|
|
||||||
|
|
||||||
// if (aCookie === undefined) {
|
|
||||||
// console.log("kosong");
|
|
||||||
// } else {
|
|
||||||
// console.log("cookie ada", aCookie);
|
|
||||||
// }
|
|
||||||
// removeCookies();
|
|
||||||
// const csrfNow = Cookies.get("csrf_");
|
|
||||||
// const sessionNow = Cookies.get("session_id");
|
|
||||||
// console.log("now", csrfNow, sessionNow);
|
|
||||||
const resCsrf = await getCsrfToken();
|
const resCsrf = await getCsrfToken();
|
||||||
const csrfToken = resCsrf?.data?.csrf_token;
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
const defaultHeaders = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
};
|
|
||||||
const mergedHeaders = {
|
const mergedHeaders = {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,72 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
import { postSignIn } from "../master-user";
|
||||||
|
import Cookies from "js-cookie";
|
||||||
|
|
||||||
const baseURL = "https://kontenhumas.com/api";
|
const baseURL = "https://dev.mikulnews.com/api";
|
||||||
|
|
||||||
|
const refreshToken = Cookies.get("refresh_token");
|
||||||
|
|
||||||
const axiosInterceptorInstance = axios.create({
|
const axiosInterceptorInstance = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
"X-Client-Key": process.env.MEDOLS_CLIENT_KEY
|
||||||
},
|
},
|
||||||
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Request interceptor
|
||||||
|
axiosInterceptorInstance.interceptors.request.use(
|
||||||
|
(config) => {
|
||||||
|
console.log("Config interceptor : ", config);
|
||||||
|
const accessToken = Cookies.get("access_token");
|
||||||
|
if (accessToken) {
|
||||||
|
if (config.headers)
|
||||||
|
config.headers.Authorization = "Bearer " + accessToken;
|
||||||
|
}
|
||||||
|
return config;
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Response interceptor
|
||||||
|
axiosInterceptorInstance.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
console.log("Response interceptor : ", response);
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
async function (error) {
|
||||||
|
console.log("Error interceptor : ", error.response.status);
|
||||||
|
const originalRequest = error.config;
|
||||||
|
if (error.response.status === 401 && !originalRequest._retry) {
|
||||||
|
originalRequest._retry = true;
|
||||||
|
const data = {
|
||||||
|
grantType: "refresh_token",
|
||||||
|
refreshToken: refreshToken,
|
||||||
|
clientId: "mediahub-app",
|
||||||
|
};
|
||||||
|
console.log("refresh token ", data);
|
||||||
|
const res = await postSignIn(data);
|
||||||
|
if (res?.error) {
|
||||||
|
Object.keys(Cookies.get()).forEach((cookieName) => {
|
||||||
|
Cookies.remove(cookieName);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const { access_token } = res?.data;
|
||||||
|
const { refresh_token } = res?.data;
|
||||||
|
if (access_token) {
|
||||||
|
Cookies.set("access_token", access_token);
|
||||||
|
Cookies.set("refresh_token", refresh_token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return axiosInterceptorInstance(originalRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
export default axiosInterceptorInstance;
|
export default axiosInterceptorInstance;
|
||||||
|
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
import axios from "axios";
|
|
||||||
import { postSignIn } from "../master-user";
|
|
||||||
import Cookies from "js-cookie";
|
|
||||||
|
|
||||||
const baseURL = "https://kontenhumas.com/api";
|
|
||||||
|
|
||||||
const refreshToken = Cookies.get("refresh_token");
|
|
||||||
|
|
||||||
const axiosInterceptorInstance = axios.create({
|
|
||||||
baseURL,
|
|
||||||
headers: {
|
|
||||||
"content-type": "application/json",
|
|
||||||
},
|
|
||||||
withCredentials: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Request interceptor
|
|
||||||
axiosInterceptorInstance.interceptors.request.use(
|
|
||||||
(config) => {
|
|
||||||
console.log("Config interceptor : ", config);
|
|
||||||
const accessToken = Cookies.get("access_token");
|
|
||||||
if (accessToken) {
|
|
||||||
if (config.headers)
|
|
||||||
config.headers.Authorization = "Bearer " + accessToken;
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
},
|
|
||||||
(error) => {
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Response interceptor
|
|
||||||
axiosInterceptorInstance.interceptors.response.use(
|
|
||||||
(response) => {
|
|
||||||
console.log("Response interceptor : ", response);
|
|
||||||
return response;
|
|
||||||
},
|
|
||||||
async function (error) {
|
|
||||||
console.log("Error interceptor : ", error.response.status);
|
|
||||||
const originalRequest = error.config;
|
|
||||||
if (error.response.status === 401 && !originalRequest._retry) {
|
|
||||||
originalRequest._retry = true;
|
|
||||||
const data = {
|
|
||||||
grantType: "refresh_token",
|
|
||||||
refreshToken: refreshToken,
|
|
||||||
clientId: "mediahub-app",
|
|
||||||
};
|
|
||||||
console.log("refresh token ", data);
|
|
||||||
const res = await postSignIn(data);
|
|
||||||
if (res?.error) {
|
|
||||||
Object.keys(Cookies.get()).forEach((cookieName) => {
|
|
||||||
Cookies.remove(cookieName);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const { access_token } = res?.data;
|
|
||||||
const { refresh_token } = res?.data;
|
|
||||||
if (access_token) {
|
|
||||||
Cookies.set("access_token", access_token);
|
|
||||||
Cookies.set("refresh_token", refresh_token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return axiosInterceptorInstance(originalRequest);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Promise.reject(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
export default axiosInterceptorInstance;
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
const baseURL = "https://kontenhumas.com/api";
|
const baseURL = "https://dev.mikulnews.com/api";
|
||||||
|
|
||||||
const axiosBaseInstance = axios.create({
|
const axiosBaseInstance = axios.create({
|
||||||
baseURL,
|
baseURL,
|
||||||
headers: {
|
headers: {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
|
"X-Client-Key": process.env.MEDOLS_CLIENT_KEY
|
||||||
},
|
},
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,21 @@
|
||||||
import axiosBaseInstance from "./axios-base-instance";
|
import axiosBaseInstance from "./http-base-instance";
|
||||||
|
|
||||||
|
const defaultHeaders = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-Client-Key": process.env.MEDOLS_CLIENT_KEY
|
||||||
|
};
|
||||||
|
|
||||||
|
export async function httpGet(pathUrl: any, headers?: any) {
|
||||||
|
|
||||||
|
const mergedHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
...headers,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Merged Headers : ", mergedHeaders);
|
||||||
|
|
||||||
export async function httpGet(pathUrl: any, headers: any) {
|
|
||||||
const response = await axiosBaseInstance
|
const response = await axiosBaseInstance
|
||||||
.get(pathUrl, { headers })
|
.get(pathUrl, { headers: mergedHeaders })
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
console.log("Response base svc : ", response);
|
console.log("Response base svc : ", response);
|
||||||
if (response?.data.success) {
|
if (response?.data.success) {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,12 @@
|
||||||
import { useRouter } from "next/navigation";
|
import { useRouter } from "next/navigation";
|
||||||
import axiosInterceptorInstance from "./axios-interceptor-instance";
|
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
|
import axiosInterceptorInstance from "./axios-interceptor-instance";
|
||||||
|
import { getCsrfToken } from "../master-user";
|
||||||
|
|
||||||
|
const defaultHeaders = {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-Client-Key": process.env.MEDOLS_CLIENT_KEY
|
||||||
|
};
|
||||||
|
|
||||||
export async function httpGetInterceptor(pathUrl: any) {
|
export async function httpGetInterceptor(pathUrl: any) {
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
|
|
@ -29,8 +35,17 @@ export async function httpGetInterceptor(pathUrl: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any) {
|
export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any) {
|
||||||
|
const resCsrf = await getCsrfToken();
|
||||||
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
|
const mergedHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
...headers,
|
||||||
|
...(csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.post(pathUrl, data, { headers })
|
.post(pathUrl, data, { headers: mergedHeaders })
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
console.log("Response interceptor : ", response);
|
console.log("Response interceptor : ", response);
|
||||||
if (response?.status == 200 || response?.status == 201) {
|
if (response?.status == 200 || response?.status == 201) {
|
||||||
|
|
@ -51,9 +66,49 @@ export async function httpPostInterceptor(pathUrl: any, data: any, headers?: any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function httpDeleteInterceptor(pathUrl: any) {
|
export async function httpPutInterceptor(pathUrl: any, data: any, headers?: any) {
|
||||||
|
const resCsrf = await getCsrfToken();
|
||||||
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
|
const mergedHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
...headers,
|
||||||
|
...(csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {}),
|
||||||
|
};
|
||||||
const response = await axiosInterceptorInstance
|
const response = await axiosInterceptorInstance
|
||||||
.delete(pathUrl)
|
.put(pathUrl, data, { headers: mergedHeaders })
|
||||||
|
.catch((error) => error.response);
|
||||||
|
console.log("Response interceptor : ", response);
|
||||||
|
if (response?.status == 200 || response?.status == 201) {
|
||||||
|
return {
|
||||||
|
error: false,
|
||||||
|
message: "success",
|
||||||
|
data: response?.data,
|
||||||
|
};
|
||||||
|
} else if (response?.status == 401) {
|
||||||
|
Cookies.set("is_logout", "true");
|
||||||
|
window.location.href = "/";
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
message: response?.data?.message || response?.data || null,
|
||||||
|
data: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function httpDeleteInterceptor(pathUrl: any, headers: any) {
|
||||||
|
const resCsrf = await getCsrfToken();
|
||||||
|
const csrfToken = resCsrf?.data?.csrf_token;
|
||||||
|
|
||||||
|
const mergedHeaders = {
|
||||||
|
...defaultHeaders,
|
||||||
|
...headers,
|
||||||
|
...(csrfToken ? { "X-CSRF-TOKEN": csrfToken } : {}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const response = await axiosInterceptorInstance
|
||||||
|
.delete(pathUrl, { headers: mergedHeaders })
|
||||||
.catch((error) => error.response);
|
.catch((error) => error.response);
|
||||||
console.log("Response interceptor : ", response);
|
console.log("Response interceptor : ", response);
|
||||||
if (response?.status == 200 || response?.status == 201) {
|
if (response?.status == 200 || response?.status == 201) {
|
||||||
|
|
|
||||||
|
|
@ -160,26 +160,5 @@ export async function getCsrfToken() {
|
||||||
const headers = {
|
const headers = {
|
||||||
"content-type": "application/json",
|
"content-type": "application/json",
|
||||||
};
|
};
|
||||||
return httpGetTemp(pathUrl, headers);
|
return httpGet(pathUrl, headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function httpGetTemp(pathUrl: any, headers: any) {
|
|
||||||
const response = await axiosBaseInstance.get(pathUrl, { headers }).catch(function (error: any) {
|
|
||||||
console.log(error);
|
|
||||||
return error.response;
|
|
||||||
});
|
|
||||||
console.log("Response base svc : ", response);
|
|
||||||
if (response?.status == 200 || response?.status == 201) {
|
|
||||||
return {
|
|
||||||
error: false,
|
|
||||||
message: "success",
|
|
||||||
data: response?.data,
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
error: true,
|
|
||||||
message: response?.data?.message || response?.data || null,
|
|
||||||
data: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue