Add api
This commit is contained in:
52
src/api/auth.jsx
Normal file
52
src/api/auth.jsx
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
import { SendRequest } from '../components/Global/ApiRequest';
|
||||||
|
import RegistrationRequest from '../components/Global/RegisterRequest';
|
||||||
|
|
||||||
|
const login = async (params) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'post',
|
||||||
|
prefix: `auth/login`,
|
||||||
|
params: params,
|
||||||
|
});
|
||||||
|
return response || [];
|
||||||
|
};
|
||||||
|
|
||||||
|
const uploadFile = async (formData) => {
|
||||||
|
const response = await RegistrationRequest({
|
||||||
|
method: 'post',
|
||||||
|
prefix: 'file-upload',
|
||||||
|
params: formData,
|
||||||
|
headers: { 'Content-Type': 'multipart/form-data' },
|
||||||
|
});
|
||||||
|
return response || {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const register = async (params) => {
|
||||||
|
const response = await RegistrationRequest({
|
||||||
|
method: 'post',
|
||||||
|
prefix: 'register',
|
||||||
|
params: params,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
});
|
||||||
|
return response || {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const verifyRedirect = async (params) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'post',
|
||||||
|
prefix: 'auth/verify-redirect',
|
||||||
|
params: params,
|
||||||
|
token: false,
|
||||||
|
});
|
||||||
|
return response || {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkUsername = async (queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix: `register/check-username?${queryParams.toString()}`,
|
||||||
|
});
|
||||||
|
return response || {};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export { login, uploadFile, register, verifyRedirect, checkUsername };
|
||||||
48
src/api/dashboard-home.jsx
Normal file
48
src/api/dashboard-home.jsx
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { SendRequest } from '../components/Global/ApiRequest';
|
||||||
|
|
||||||
|
const getTotal = async (query = '') => {
|
||||||
|
const prefix = `${query ? `?${query}` : ''}`;
|
||||||
|
const fullUrl = `${import.meta.env.VITE_API_SERVER}/dashboard/${prefix}`;
|
||||||
|
try {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix: `dashboard/${prefix}`,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[API Call] Failed: GET ${fullUrl}`, error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTotalPermit = async (query = '') => {
|
||||||
|
const prefix = `dashboard/permit-total${query ? `?${query}` : ''}`;
|
||||||
|
const fullUrl = `${import.meta.env.VITE_API_SERVER}/${prefix}`;
|
||||||
|
try {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[API Call] Failed: GET ${fullUrl}`, error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const getTotalPermitPerYear = async (query = '') => {
|
||||||
|
const prefix = `dashboard/permit-breakdown${query ? `?${query}` : ''}`;
|
||||||
|
const fullUrl = `${import.meta.env.VITE_API_SERVER}/${prefix}`;
|
||||||
|
try {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`[API Call] Failed: GET ${fullUrl}`, error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { getTotal, getTotalPermit, getTotalPermitPerYear };
|
||||||
45
src/api/master-apd.jsx
Normal file
45
src/api/master-apd.jsx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { SendRequest } from '../components/Global/ApiRequest';
|
||||||
|
|
||||||
|
const getAllApd = async (queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix: `apd?${queryParams.toString()}`,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
const createApd = async (queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'post',
|
||||||
|
prefix: `apd`,
|
||||||
|
params: queryParams,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateApd = async (vendor_id, queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'put',
|
||||||
|
prefix: `apd/${vendor_id}`,
|
||||||
|
params: queryParams,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteApd = async (queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'delete',
|
||||||
|
prefix: `apd/${queryParams}`,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getJenisPermit = async () => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix: `apd/jenis-permit`,
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export { getAllApd, createApd, updateApd, deleteApd, getJenisPermit };
|
||||||
84
src/api/user-admin.jsx
Normal file
84
src/api/user-admin.jsx
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
// user-admin.jsx
|
||||||
|
import axios from 'axios';
|
||||||
|
import { SendRequest } from '../components/Global/ApiRequest';
|
||||||
|
|
||||||
|
const baseURL = import.meta.env.VITE_API_SERVER;
|
||||||
|
|
||||||
|
const getAllUser = async (queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix: `admin-user?${queryParams.toString()}`,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getUserDetail = async (id) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'get',
|
||||||
|
prefix: `admin-user/${id}`,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
const updateUser = async (id, data) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'put',
|
||||||
|
prefix: `admin-user/${id}`,
|
||||||
|
params: data,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteUser = async (id) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'delete',
|
||||||
|
prefix: `admin-user/${id}`,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
const approvalUser = async (id, queryParams) => {
|
||||||
|
const response = await SendRequest({
|
||||||
|
method: 'post',
|
||||||
|
prefix: `admin-user/approve/${id}`,
|
||||||
|
params: queryParams,
|
||||||
|
});
|
||||||
|
return response;
|
||||||
|
};
|
||||||
|
|
||||||
|
const uploadFile = async (formData) => {
|
||||||
|
try {
|
||||||
|
const token = localStorage.getItem('token')?.replace(/"/g, '') || '';
|
||||||
|
const url = `${baseURL}/file-upload`;
|
||||||
|
|
||||||
|
const response = await axios.post(url, formData, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
'Accept-Language': 'en_US',
|
||||||
|
'Content-Type': 'multipart/form-data',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
statusCode: response.data?.statusCode ?? 0,
|
||||||
|
message: response.data?.message ?? '',
|
||||||
|
data: response.data?.data ?? {},
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ ERROR di uploadFile:', error);
|
||||||
|
return {
|
||||||
|
statusCode: error?.response?.status || 500,
|
||||||
|
message: error?.response?.data?.message || 'Upload gagal',
|
||||||
|
data: {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export { getAllUser, getUserDetail, updateUser, deleteUser, approvalUser, uploadFile };
|
||||||
Reference in New Issue
Block a user