chore: build
This commit is contained in:
@@ -207,14 +207,44 @@ export const getAdminStatsByMonth = async (
|
||||
);
|
||||
return data;
|
||||
};
|
||||
export const getAllClients = async (): Promise<ClientResponse[]> => {
|
||||
const { data } = await apiClient.get(`${V2}/admin/protected/all/clients`);
|
||||
return data.clients || [];
|
||||
export interface AdminUserItem {
|
||||
id: number;
|
||||
username: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
export interface PagedResult<T> {
|
||||
items: T[];
|
||||
total: number;
|
||||
hasMore: boolean;
|
||||
}
|
||||
|
||||
export const getAllClients = async (
|
||||
offset = 0,
|
||||
limit = 100,
|
||||
): Promise<PagedResult<ClientResponse>> => {
|
||||
const { data } = await apiClient.get(`${V2}/admin/protected/all/clients`, {
|
||||
params: { limit, offset },
|
||||
});
|
||||
return {
|
||||
items: data.clients || [],
|
||||
total: data.count ?? 0,
|
||||
hasMore: !!data.has_more,
|
||||
};
|
||||
};
|
||||
|
||||
export const getAllUsers = async () => {
|
||||
const { data } = await apiClient.get(`${V2}/admin/protected/all/users`);
|
||||
return data.users || [];
|
||||
export const getAllUsers = async (
|
||||
offset = 0,
|
||||
limit = 100,
|
||||
): Promise<PagedResult<AdminUserItem>> => {
|
||||
const { data } = await apiClient.get(`${V2}/admin/protected/all/users`, {
|
||||
params: { limit, offset },
|
||||
});
|
||||
return {
|
||||
items: data.users || [],
|
||||
total: data.count ?? 0,
|
||||
hasMore: !!data.has_more,
|
||||
};
|
||||
};
|
||||
|
||||
export const updateClientByAdmin = async (
|
||||
@@ -489,60 +519,37 @@ export const getAllDeliveryPersonsWithDetails = async (): Promise<{
|
||||
stats: DeliveryPersonsStats;
|
||||
}> => {
|
||||
try {
|
||||
// Le backend renvoie désormais statut/position/compteurs déjà
|
||||
// enrichis pour tous les livreurs en un seul appel (voir
|
||||
// GetDeliveryPersonsDetailsBatch côté backend) : plus besoin d'un
|
||||
// aller-retour /delivery-persons/:username par livreur ici.
|
||||
const { data } = await apiClient.get(
|
||||
`${V2}/admin/protected/delivery-persons`,
|
||||
);
|
||||
const livreurs = data.livreurs || [];
|
||||
|
||||
const enriched = await Promise.all(
|
||||
livreurs.map(async (l: any): Promise<DeliveryPerson> => {
|
||||
try {
|
||||
const details = await getDeliveryPersonDetails(l.username);
|
||||
const parsedStatus = parseStatus(details.status);
|
||||
const hasLoc =
|
||||
details.location?.latitude &&
|
||||
details.location?.longitude;
|
||||
return {
|
||||
id: l.id,
|
||||
username: l.username,
|
||||
status: parsedStatus,
|
||||
location: {
|
||||
latitude: hasLoc ? details.location.latitude : 0,
|
||||
longitude: hasLoc ? details.location.longitude : 0,
|
||||
last_update: details.location?.last_update
|
||||
? new Date(
|
||||
details.location.last_update * 1000,
|
||||
).toISOString()
|
||||
: new Date().toISOString(),
|
||||
is_recent: details.location?.is_recent || false,
|
||||
},
|
||||
stats: {
|
||||
total_deliveries: details.total_deliveries || 0,
|
||||
completed_today: details.completed_deliveries || 0,
|
||||
queue_size: details.queue_size || 0,
|
||||
current_command: details.current_command || null,
|
||||
},
|
||||
};
|
||||
} catch {
|
||||
return {
|
||||
id: l.id,
|
||||
username: l.username,
|
||||
status: "offline",
|
||||
location: {
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
last_update: new Date().toISOString(),
|
||||
is_recent: false,
|
||||
},
|
||||
stats: {
|
||||
total_deliveries: 0,
|
||||
completed_today: 0,
|
||||
queue_size: 0,
|
||||
current_command: null,
|
||||
},
|
||||
};
|
||||
}
|
||||
}),
|
||||
const enriched: DeliveryPerson[] = livreurs.map(
|
||||
(l: any): DeliveryPerson => {
|
||||
const parsedStatus = parseStatus(l.status);
|
||||
const hasLoc = l.location?.latitude && l.location?.longitude;
|
||||
return {
|
||||
id: l.id,
|
||||
username: l.username,
|
||||
status: parsedStatus,
|
||||
location: {
|
||||
latitude: hasLoc ? l.location.latitude : 0,
|
||||
longitude: hasLoc ? l.location.longitude : 0,
|
||||
last_update: new Date().toISOString(),
|
||||
is_recent: false,
|
||||
},
|
||||
stats: {
|
||||
total_deliveries: l.total_deliveries || 0,
|
||||
completed_today: l.completed_deliveries || 0,
|
||||
queue_size: l.queue_size || 0,
|
||||
current_command: l.current_command || null,
|
||||
},
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
const stats: DeliveryPersonsStats = {
|
||||
@@ -755,6 +762,22 @@ export const getClientReferralAdmin = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const resetClientRateLimit = async (
|
||||
username: string,
|
||||
): Promise<{ success: boolean; error?: string }> => {
|
||||
try {
|
||||
await apiClient.post(
|
||||
`${V2}/admin/protected/client/${username}/ratelimit/reset`,
|
||||
);
|
||||
return { success: true };
|
||||
} catch (e: any) {
|
||||
return {
|
||||
success: false,
|
||||
error: e.response?.data?.error || "Erreur levée du rate limit",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export const resetClientReferral = async (
|
||||
username: string,
|
||||
): Promise<{ success: boolean; message?: string }> => {
|
||||
|
||||
Reference in New Issue
Block a user