feat: update fixing user services

This commit is contained in:
hanif salafi 2025-07-03 21:55:53 +07:00
parent af9000498a
commit b76f661b80
3 changed files with 34 additions and 70 deletions

View File

@ -33,9 +33,13 @@ export async function httpGet(pathUrl: any, headers?: any) {
}
}
export async function httpPost(pathUrl: any, headers: any, data: any) {
export async function httpPost(pathUrl: any, data: any, headers?: any) {
const mergedHeaders = {
...defaultHeaders,
...headers,
};
const response = await axiosBaseInstance
.post(pathUrl, data, { headers })
.post(pathUrl, data, { headers: mergedHeaders })
.catch(function (error) {
console.log(error);
return error.response;

View File

@ -98,7 +98,7 @@ export async function httpPutInterceptor(pathUrl: any, data: any, headers?: any)
}
}
export async function httpDeleteInterceptor(pathUrl: any, headers: any) {
export async function httpDeleteInterceptor(pathUrl: any, headers?: any) {
const resCsrf = await getCsrfToken();
const csrfToken = resCsrf?.data?.csrf_token;

View File

@ -1,6 +1,6 @@
import { httpDeleteInterceptor, httpGet, httpPost, httpPut } from "./http-config/axios-base-service";
import Cookies from "js-cookie";
import axiosBaseInstance from "./http-config/http-base-instance";
import { httpGet, httpPost } from "./http-config/http-base-services";
import { httpDeleteInterceptor, httpGetInterceptor, httpPostInterceptor, httpPutInterceptor } from "./http-config/http-interceptor-services";
const token = Cookies.get("access_token");
const id = Cookies.get("uie");
@ -13,46 +13,32 @@ export async function listMasterUsers(data: any) {
}
export async function createMasterUser(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/users`;
return await httpPost(pathUrl, headers, data);
return await httpPostInterceptor(pathUrl, data);
}
export async function emailValidation(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/users/email-validation`;
return await httpPost(pathUrl, headers, data);
return await httpPost(pathUrl, data);
}
export async function setupEmail(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/users/setup-email`;
return await httpPost(pathUrl, headers, data);
return await httpPost(pathUrl, data);
}
export async function getDetailMasterUsers(id: string) {
const headers = {
"content-type": "application/json",
};
return await httpGet(`/users/detail/${id}`, headers);
const pathUrl = `/users/detail/${id}`;
return await httpGetInterceptor(pathUrl);
}
export async function editMasterUsers(data: any, id: string) {
const headers = {
"content-type": "application/json",
};
return await httpPut(`/users/${id}`, headers, data);
const pathUrl = `/users/${id}`
return await httpPutInterceptor(pathUrl, data);
}
export async function deleteMasterUser(id: string) {
const headers = {
"content-type": "application/json",
};
return await httpDeleteInterceptor(`/users/${id}`, headers);
const pathUrl = `/users/${id}`
return await httpDeleteInterceptor(pathUrl);
}
export async function postSignIn(data: any) {
@ -73,18 +59,12 @@ export async function getProfile(code?: string) {
}
export async function updateProfile(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
return await httpPut(`/users/${id}`, headers, data);
const pathUrl = `/users/${id}`;
return await httpPutInterceptor(pathUrl, data);
}
export async function savePassword(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
return await httpPost(`/users/save-password`, headers, data);
const pathUrl = `/users/save-password`
return await httpPostInterceptor(pathUrl, data);
}
export async function resetPassword(data: any) {
@ -102,23 +82,13 @@ export async function checkUsernames(username: string) {
}
export async function otpRequest(email: string, name: string) {
const headers = {
"content-type": "application/json",
};
return await httpPost(`/users/otp-request`, headers, { email, name });
const pathUrl = `/users/otp-request`;
return await httpPost(pathUrl, { email, name });
}
export async function otpValidation(email: string, otpCode: string) {
const headers = {
"content-type": "application/json",
};
return await httpPost(`/users/otp-validation`, headers, { email, otpCode });
}
export async function otpValidationLogin(data: any) {
const headers = {
"content-type": "application/json",
};
return await httpPost(`/users/otp-validation`, headers, data);
const pathUrl = `/users/otp-validation`
return await httpPost(pathUrl, { email, otpCode });
}
export async function postArticleComment(data: any) {
@ -134,31 +104,21 @@ export async function postArticleComment(data: any) {
}
export async function editArticleComment(data: any, id: number) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
return await httpPut(`/article-comments/${id}`, headers, data);
const pathUrl = `/article-comments/${id}`;
return await httpPutInterceptor(pathUrl, data);
}
export async function getArticleComment(id: string) {
const headers = {
"content-type": "application/json",
};
return await httpGet(`/article-comments?isPublic=true&articleId=${id}`, headers);
const pathUrl = `/article-comments?isPublic=true&articleId=${id}`;
return await httpGet(pathUrl);
}
export async function deleteArticleComment(id: number) {
const headers = {
"content-type": "application/json",
};
return await httpDeleteInterceptor(`/article-comments/${id}`, headers);
const pathUrl = `/article-comments/${id}`
return await httpDeleteInterceptor(pathUrl);
}
export async function getCsrfToken() {
const pathUrl = "csrf-token";
const headers = {
"content-type": "application/json",
};
return httpGet(pathUrl, headers);
return httpGet(pathUrl);
}