chore: features category

This commit is contained in:
2026-03-07 15:10:18 +01:00
parent f66efee59c
commit dd31473ca1
13 changed files with 433 additions and 62 deletions
+72 -2
View File
@@ -9,8 +9,8 @@ import type {
Alert,
} from "./types";
const V2 = "https://uber-stup.club/api/v2";
const CABINE_URL = "https://uber-stup.club/api/v1/cabine";
const V2 = "http://5.181.0.112/api/v2";
const CABINE_URL = "http://5.181.0.112/api/v1/cabine";
// ============================================
// AUTH
@@ -580,3 +580,73 @@ export const getCommandCountByStatus = async (
return 0;
}
};
// ============================================
// CATÉGORIES
// ============================================
const V1_PUBLIC = "https://uber-stup.club/api/v1";
export interface Category {
id: number;
name: string;
created_at: string;
}
export const getCategories = async (): Promise<Category[]> => {
try {
const { data } = await apiClient.get(`${V1_PUBLIC}/categories`);
return data.categories || [];
} catch {
return [];
}
};
export const createCategoryAdmin = async (
name: string,
): Promise<{ success: boolean; category?: Category; error?: string }> => {
try {
const { data } = await apiClient.post(
`${V2}/admin/protected/categories`,
{ name },
);
return { success: true, category: data.category };
} catch (error: any) {
return {
success: false,
error: error.response?.data?.error || "Erreur",
};
}
};
export const updateCategoryAdmin = async (
id: number,
name: string,
): Promise<{ success: boolean; category?: Category; error?: string }> => {
try {
const { data } = await apiClient.put(
`${V2}/admin/protected/categories/${id}`,
{ name },
);
return { success: true, category: data.category };
} catch (error: any) {
return {
success: false,
error: error.response?.data?.error || "Erreur",
};
}
};
export const deleteCategoryAdmin = async (
id: number,
): Promise<{ success: boolean; error?: string }> => {
try {
await apiClient.delete(`${V2}/admin/protected/categories/${id}`);
return { success: true };
} catch (error: any) {
return {
success: false,
error: error.response?.data?.error || "Erreur",
};
}
};