web-humas-fe/services/master-user.ts

209 lines
5.5 KiB
TypeScript
Raw Normal View History

2025-04-11 06:38:38 +00:00
import axiosInterceptorInstance from "@/services/http-config/axios-interceptor-instance";
import {
httpDeleteInterceptor,
httpGet,
httpPost,
httpPut,
} from "./http-config/axios-base-service";
import Cookies from "js-cookie";
2025-05-04 07:14:12 +00:00
import axiosBaseInstance from "./http-config/http-base-instance";
const token = Cookies.get("access_token");
const id = Cookies.get("uie");
2024-04-24 10:10:26 +00:00
export async function listMasterUsers(data: any) {
const headers = {
"content-type": "application/json",
};
2025-05-27 08:13:31 +00:00
return await httpGet(
`/users?page=${data.page}&limit=${data.limit}&username=${
data.username || ""
2025-05-28 06:56:41 +00:00
}&fullname=${data.fullname || ""}&email=${data.email || ""}&timeStamp=${
data.timeStamp || ""
}`,
2025-05-27 08:13:31 +00:00
headers
);
2024-04-24 10:10:26 +00:00
}
export async function createMasterUser(data: any) {
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
};
const pathUrl = `/users`;
return await httpPost(pathUrl, headers, data);
2024-04-24 10:10:26 +00:00
}
export async function emailValidation(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/users/email-validation`;
return await httpPost(pathUrl, headers, data);
}
export async function setupEmail(data: any) {
const headers = {
"content-type": "application/json",
};
const pathUrl = `/users/setup-email`;
return await httpPost(pathUrl, headers, data);
}
2024-04-24 10:10:26 +00:00
2025-02-11 06:01:48 +00:00
export async function getDetailMasterUsers(id: string) {
const headers = {
"content-type": "application/json",
};
return await httpGet(`/users/detail/${id}`, headers);
}
export async function editMasterUsers(data: any, id: string) {
2025-02-11 06:01:48 +00:00
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
2025-02-11 06:01:48 +00:00
};
return await httpPut(`/users/${id}`, headers, data);
}
2024-04-24 10:10:26 +00:00
export async function deleteMasterUser(id: string) {
2025-03-18 08:30:18 +00:00
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
2025-03-18 08:30:18 +00:00
};
return await httpDeleteInterceptor(`/users/${id}`, headers);
}
export async function postSignIn(data: any) {
const headers = {
2025-04-11 06:38:38 +00:00
accept: "application/json",
"content-type": "application/json",
};
const pathUrl = `/users/login`;
return await httpPost(pathUrl, headers, data);
}
export async function getProfile(code?: string) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${code || token}`,
};
return await httpGet(`/users/info`, headers);
}
export async function updateProfile(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
return await httpPut(`/users/${id}`, headers, data);
}
export async function savePassword(data: any) {
const headers = {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
};
return await httpPost(`/users/save-password`, headers, data);
}
export async function resetPassword(data: any) {
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
};
return await httpPost(`/users/reset-password`, headers, data);
}
export async function checkUsernames(username: string) {
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
};
return await httpPost(`/users/forgot-password`, headers, { username });
}
2025-01-31 12:42:40 +00:00
export async function otpRequest(email: string, name: string) {
const headers = {
"content-type": "application/json",
};
2025-01-31 12:42:40 +00:00
return await httpPost(`/users/otp-request`, headers, { 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);
}
2025-01-31 12:42:40 +00:00
export async function postArticleComment(data: any) {
2025-02-07 09:37:39 +00:00
const headers = token
? {
"content-type": "application/json",
Authorization: `Bearer ${token}`,
}
: {
"content-type": "application/json",
};
2025-01-31 12:42:40 +00:00
return await httpPost(`/article-comments`, headers, data);
}
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);
}
export async function getArticleComment(id: string) {
const headers = {
"content-type": "application/json",
};
2025-03-06 14:58:38 +00:00
return await httpGet(
`/article-comments?isPublic=true&articleId=${id}`,
headers
);
2025-01-31 12:42:40 +00:00
}
export async function deleteArticleComment(id: number) {
2025-03-18 08:30:18 +00:00
const headers = {
"content-type": "application/json",
2025-08-29 06:43:53 +00:00
Authorization: `Bearer ${token}`,
2025-03-18 08:30:18 +00:00
};
return await httpDeleteInterceptor(`/article-comments/${id}`, headers);
2025-01-31 12:42:40 +00:00
}
2025-04-11 06:38:38 +00:00
export async function getCsrfToken() {
const pathUrl = "csrf-token";
const headers = {
"content-type": "application/json",
};
return httpGetTemp(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;
});
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,
};
}
}