chore: add create user route
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
// ✅ loginUser et registerUser retournent AuthResponse
|
||||
// ✅ sessionStorage (pas localStorage)
|
||||
|
||||
const API_URL = "/api/v1";
|
||||
const API_URL = "http://localhost:8080/api/v1";
|
||||
import type {
|
||||
ConfirmReceptionResponse,
|
||||
CheckoutCartResponse,
|
||||
|
||||
@@ -15,7 +15,7 @@ import type {
|
||||
DeliveryPersonDetails,
|
||||
DeliveryPersonStats,
|
||||
} from "./api_admin_types";
|
||||
const API_URL = "/api/v2";
|
||||
const API_URL = "http://localhost:8080/api/v2";
|
||||
|
||||
// ============================================
|
||||
// 🔐 TYPES - ADMIN
|
||||
@@ -2583,6 +2583,50 @@ export const deleteAlertAdmin = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const CreateUser = async (
|
||||
username: string,
|
||||
password: string,
|
||||
role: string,
|
||||
) => {
|
||||
try {
|
||||
const token = sessionStorage.getItem("admin_token");
|
||||
const response = await fetch(`${API_URL}/admin/protected/users`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify({ username, password, role }),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
console.error("❌ [CREATE_USER] Erreur API:", data);
|
||||
return {
|
||||
success: false,
|
||||
error: data.error || "Erreur création utilisateur",
|
||||
};
|
||||
}
|
||||
|
||||
console.log("✅ [CREATE_USER] Utilisateur créé avec succès");
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: data.message || "Utilisateur créé avec succès",
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("❌ [CREATE_USER] Erreur fetch:", error);
|
||||
return {
|
||||
success: false,
|
||||
error:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "Erreur réseau inconnue",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// ============================================
|
||||
// 🔄 EXPORT PAR DÉFAUT
|
||||
// ============================================
|
||||
@@ -2592,6 +2636,7 @@ export default {
|
||||
registerAdmin,
|
||||
loginAdmin,
|
||||
logoutAdmin,
|
||||
CreateUser,
|
||||
|
||||
// JWT Utils
|
||||
extractAdminUsernameFromToken,
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
// ✅ Utilise /api/v1/cabine/* endpoints uniquement
|
||||
// ✅ sessionStorage pour la persistance
|
||||
|
||||
const API_URL = "/api/v1/cabine";
|
||||
const API_URL = "http://localhost:8080/api/v1/cabine";
|
||||
import type {
|
||||
DeliveryPerson,
|
||||
DeliveryPersonsStats,
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// ✅ Fonctions helper pour le dashboard livreur
|
||||
// ✅ Utilise /api/v1/livreur/* endpoints
|
||||
|
||||
const API_URL = "/api/v1/livreur";
|
||||
const API_URL = "http://localhost:8080/api/v1/livreur";
|
||||
|
||||
// ============================================
|
||||
// 🔐 TYPES - LIVREUR
|
||||
|
||||
Reference in New Issue
Block a user