Used in: app/Auth/Login.tsx, app/Auth/ResetPassword.tsx
// Login
await authApi.login({u: 'username', p: 'password'}, 'admin');
// Forgot Password
await authApi.forgotPassword({email: 'user@example.com'});Used in: app/DashboardScreen/ManajemenProduk.tsx, app/Forms/FormProdukScreen.tsx, app/DashboardScreen/Dashboard.tsx
// Get all products with pagination and search
await productsApi.getAll({page: 1, limit: 10, q: 'search'});
// Create product
await productsApi.create(productData);
// Update product
await productsApi.update(productId, updatedData);
// Delete product
await productsApi.delete(productId);
// Update product status
await productsApi.update(productId, {status_produk: 'disetujui'});Used in: app/DashboardScreen/ManajemenMitra.tsx, app/DashboardScreen/Dashboard.tsx
// Get all users
await usersApi.getAll();
// Get user products
await usersApi.getProducts(userId);
// Get user profile
await usersApi.getOwnProfile();Used in: app/DashboardScreen/Dashboard.tsx, app/Forms/FormProdukScreen.tsx, app/DashboardScreen/ManajemenKategoriUsaha.tsx
// Get business categories
await masterDataApi.getBusinessCategories();
// Get user levels
await masterDataApi.getUserLevels();
// Get subsectors
await masterDataApi.getSubsectors();Used in: app/DashboardScreen/ManajemenKategoriUsaha.tsx
// Get all categories
await masterDataApi.getBusinessCategories();
// Create category
await kategoriUsahaApi.create(categoryData);
// Update category
await kategoriUsahaApi.update(categoryId, updatedData);
// Delete category
await kategoriUsahaApi.delete(categoryId);Used in: app/Forms/FormProdukScreen.tsx, app/DashboardScreen/ManajemenKategoriUsaha.tsx
// Upload image
const imageUrl = await uploaderApi.uploadImage(imageAsset);usersApi.getAll()- Get all users for statisticsproductsApi.getAll({limit: 10})- Get recent productsmasterDataApi.getBusinessCategories()- Get categories count
productsApi.getAll({page, limit, q})- Get products with pagination/searchproductsApi.update(id, {status_produk})- Update product statusproductsApi.delete(id)- Delete product
usersApi.getAll()- Get all usersusersApi.getProducts(userId)- Get products for each user
masterDataApi.getBusinessCategories()- Get categorieskategoriUsahaApi.create(data)- Create new categorykategoriUsahaApi.update(id, data)- Update categorykategoriUsahaApi.delete(id)- Delete categoryuploaderApi.uploadImage(asset)- Upload category image
masterDataApi.getBusinessCategories()- Get categories for dropdownuploaderApi.uploadImage(asset)- Upload product imageproductsApi.create(data)- Create new productproductsApi.update(id, data)- Update existing product
authApi.login({u, p}, level)- User authentication
authApi.forgotPassword({email})- Request password reset
All API clients are defined in lib/api.ts and follow this pattern:
export const apiName = {
method: (params) =>
client
.httpMethod<ResponseType>(endpoint, data)
.then(res => res.data)
.catch(e => handleError(e, 'context')),
};All APIs use consistent error handling:
const handleError = (error: any, context: string): never => {
console.error(`API Error in ${context}:`, JSON.stringify(error, null, 2));
if (axios.isAxiosError(error)) {
if (!error.response) {
throw new Error('Tidak dapat terhubung ke server. Periksa koneksi internet Anda.');
}
throw new Error(error.response.data.message ?? `Gagal ${context}.`);
}
throw new Error(`Terjadi kesalahan tidak terduga saat ${context}.`);
};- User logs in via
authApi.login() - JWT token is stored in AsyncStorage
- Token is automatically added to all private API calls via Axios interceptor
- User data is stored in AsyncStorage for app state
- User selects image using
react-native-image-picker - Image is uploaded to external service via
uploaderApi.uploadImage() - Returned URL is used in product/category data
- Data is saved via respective API endpoints
POST /api/auth/login/{level}- LoginPOST /api/auth/register/umkm- Register UMKMPOST /api/auth/forgot-password- Forgot passwordPOST /api/auth/reset-password- Reset password
GET /api/products- Get products (with filters)GET /api/products/{id}- Get product by IDPOST /api/products- Create productPUT /api/products/{id}- Update productDELETE /api/products/{id}- Delete productPOST /api/products/{id}/links- Add store linkPUT /api/products/{id}/links/{linkId}- Update store link
GET /api/users- Get all users (admin only)GET /api/users/profile- Get current user profileGET /api/users/{id}- Get user by IDPUT /api/users/{id}- Update userDELETE /api/users/{id}- Delete userGET /api/users/{id}/products- Get user productsGET /api/users/{id}/articles- Get user articles
GET /api/business-categories- Get all categoriesGET /api/business-categories/{id}- Get category by IDPOST /api/business-categories- Create categoryPUT /api/business-categories/{id}- Update categoryDELETE /api/business-categories/{id}- Delete category
GET /api/master-data/business-categories- Get business categoriesGET /api/master-data/levels- Get user levelsGET /api/master-data/subsectors- Get subsectors
GET /api/articles- Get all articlesGET /api/articles/{id}- Get article by IDPOST /api/articles- Create articlePUT /api/articles/{id}- Update articleDELETE /api/articles/{id}- Delete article
GET /api/subsectors- Get all subsectorsGET /api/subsectors/{id}- Get subsector by IDPOST /api/subsectors- Create subsectorPUT /api/subsectors/{id}- Update subsectorDELETE /api/subsectors/{id}- Delete subsector
All API types are defined in lib/types.ts and match the OpenAPI specification:
- User-related types:
User,UserProfile,RegistrationData - Product-related types:
Product,ProductPayload,OnlineStoreLink - Category-related types:
BusinessCategory,KategoriUsaha - Response types:
ApiResponse<T>,PaginatedApiResponse<T>,ApiMessageResponse - Error types:
ErrorResponse,ValidationError
This comprehensive overview shows all API usage patterns in the Ekraf Admin application.