feat: fixing http service & config

This commit is contained in:
hanif salafi 2025-07-08 11:41:50 +07:00
parent 47402ea655
commit bee5dcadb6
5 changed files with 8 additions and 17 deletions

View File

@ -230,8 +230,5 @@ export async function deleteSPIT(id: any) {
export async function postActivityLog(data: any) { export async function postActivityLog(data: any) {
const url = `activity`; const url = `activity`;
const headers = { return httpPost(url, data);
"content-type": "application/json",
};
return httpPost(url, headers, data);
} }

View File

@ -4,7 +4,7 @@ import Cookies from "js-cookie";
import qs from "qs"; import qs from "qs";
import { getCsrfToken } from "../auth"; import { getCsrfToken } from "../auth";
export async function httpPost(pathUrl: any, headers: any, data?: any) { export async function httpPost(pathUrl: any, data?: any, headers?: any,) {
const resCsrf = await getCsrfToken(); const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.token; const csrfToken = resCsrf?.data?.token;
const authToken = Cookies.get("access_token"); const authToken = Cookies.get("access_token");
@ -15,9 +15,9 @@ export async function httpPost(pathUrl: any, headers: any, data?: any) {
const mergedHeaders = { const mergedHeaders = {
...defaultHeaders, ...defaultHeaders,
...headers,
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}), ...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
...(authToken ? { "Authorization" : `Bearer ${authToken}`} : {}), ...(authToken ? { "Authorization" : `Bearer ${authToken}`} : {}),
...headers,
}; };
const response = await axiosBaseInstance const response = await axiosBaseInstance

View File

@ -74,8 +74,8 @@ export async function httpPostInterceptor(
}; };
const mergedHeaders = { const mergedHeaders = {
...defaultHeaders, ...defaultHeaders,
...headers,
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}), ...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
...headers,
}; };
const response = await axiosInterceptorInstance const response = await axiosInterceptorInstance
@ -115,8 +115,8 @@ export async function httpPutInterceptor(
}; };
const mergedHeaders = { const mergedHeaders = {
...defaultHeaders, ...defaultHeaders,
...headers,
...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}), ...(csrfToken ? { "X-XSRF-TOKEN": csrfToken } : {}),
...headers,
}; };
const response = await axiosInterceptorInstance const response = await axiosInterceptorInstance

View File

@ -255,18 +255,12 @@ export async function getUserNotifications(page = 0, typeId: any) {
export async function forgotPassword(username: any) { export async function forgotPassword(username: any) {
const url = `forgot-password?username=${username}`; const url = `forgot-password?username=${username}`;
const header = { return httpPost(url);
"content-Type": "application/json",
};
return httpPost(url, header);
} }
export async function saveUserReports(data: any) { export async function saveUserReports(data: any) {
const url = "public/users/reports"; const url = "public/users/reports";
const header = { return httpPostInterceptor(url, data);
"content-Type": "application/json",
};
return httpPost(url, header);
} }
export async function listCarousel() { export async function listCarousel() {

View File

@ -8,7 +8,7 @@ export async function login(data: any) {
const headers = { const headers = {
"content-type": "application/json", "content-type": "application/json",
}; };
return await httpPost(pathUrl, headers, data); return await httpPost(pathUrl, data, headers);
} }
export async function userInfo(token: any) { export async function userInfo(token: any) {