chore: build
Backend - Build & Lint / build (push) Successful in 32m22s
Frontend Admin - EAS Build / build (push) Successful in 1h39m14s

This commit is contained in:
Cameron Foussard
2026-11-03 09:12:36 +01:00
parent 0a18460f13
commit ae89d995d2
5 changed files with 98 additions and 15 deletions
+33
View File
@@ -25,6 +25,39 @@ func (d *Database) GetAllUsers(limit, offset int) ([]*models.User, int64, error)
return users, total, nil return users, total, nil
} }
// UserCounts contient les totaux globaux (non paginés) affichés côté admin.
// Les usernames présents à la fois dans users et clients ne sont comptés
// qu'une fois, comme dans la liste fusionnée du front.
type UserCounts struct {
All int64 `json:"all" gorm:"column:all_count"`
Client int64 `json:"client" gorm:"column:client_count"`
Livreur int64 `json:"livreur" gorm:"column:livreur_count"`
Cabine int64 `json:"cabine" gorm:"column:cabine_count"`
Admin int64 `json:"admin" gorm:"column:admin_count"`
}
func (d *Database) GetUserCounts() (*UserCounts, error) {
var counts UserCounts
err := d.GDB.Raw(`
WITH merged AS (
SELECT username, role FROM users
UNION
SELECT c.username, 'client' AS role FROM clients c
WHERE NOT EXISTS (SELECT 1 FROM users u WHERE u.username = c.username)
)
SELECT
COUNT(DISTINCT username) AS all_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'client') AS client_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'livreur') AS livreur_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'cabine') AS cabine_count,
COUNT(DISTINCT username) FILTER (WHERE role = 'admin') AS admin_count
FROM merged`).Scan(&counts).Error
if err != nil {
return nil, fmt.Errorf("erreur lors du comptage des utilisateurs par rôle: %w", err)
}
return &counts, nil
}
func (d *Database) GetAllDeliveryMen() ([]*models.User, error) { func (d *Database) GetAllDeliveryMen() ([]*models.User, error) {
var users []*models.User var users []*models.User
if err := d.GDB.Where("role = ?", "livreur").Limit(100).Find(&users).Error; err != nil { if err := d.GDB.Where("role = ?", "livreur").Limit(100).Find(&users).Error; err != nil {
+13 -2
View File
@@ -544,11 +544,22 @@ func GetAllUsers(c *gin.Context) {
log.Printf("✅ [GET_ALL_USERS] %d users récupérés (offset=%d, total=%d)", len(sanitized), offset, total) log.Printf("✅ [GET_ALL_USERS] %d users récupérés (offset=%d, total=%d)", len(sanitized), offset, total)
c.JSON(http.StatusOK, gin.H{ resp := gin.H{
"users": sanitized, "users": sanitized,
"count": total, "count": total,
"has_more": int64(offset+len(users)) < total, "has_more": int64(offset+len(users)) < total,
}) }
// Totaux globaux par rôle (indépendants de la pagination) : uniquement
// sur la première page, c'est là que le front les lit.
if offset == 0 {
if counts, err := database.GetUserCounts(); err != nil {
log.Printf("⚠️ [GET_ALL_USERS] Comptage par rôle impossible: %v", err)
} else {
resp["counts"] = counts
}
}
c.JSON(http.StatusOK, resp)
} }
func GetAllDeliveryMen(c *gin.Context) { func GetAllDeliveryMen(c *gin.Context) {
+11 -1
View File
@@ -233,10 +233,19 @@ export const getAllClients = async (
}; };
}; };
// Totaux globaux (toute la base, pas seulement la page chargée).
export interface UserCounts {
all: number;
client: number;
livreur: number;
cabine: number;
admin: number;
}
export const getAllUsers = async ( export const getAllUsers = async (
offset = 0, offset = 0,
limit = 100, limit = 100,
): Promise<PagedResult<AdminUserItem>> => { ): Promise<PagedResult<AdminUserItem> & { counts?: UserCounts }> => {
const { data } = await apiClient.get(`${V2}/admin/protected/all/users`, { const { data } = await apiClient.get(`${V2}/admin/protected/all/users`, {
params: { limit, offset }, params: { limit, offset },
}); });
@@ -244,6 +253,7 @@ export const getAllUsers = async (
items: data.users || [], items: data.users || [],
total: data.count ?? 0, total: data.count ?? 0,
hasMore: !!data.has_more, hasMore: !!data.has_more,
counts: data.counts ?? undefined,
}; };
}; };
@@ -18,6 +18,7 @@ import { useAuth } from "../../auth/AuthContext";
import { import {
getAllCommands, getAllCommands,
getAllClients, getAllClients,
getAllUsers,
getAvailableDeliveryPersons, getAvailableDeliveryPersons,
getCommandCountByStatus, getCommandCountByStatus,
getAdminTelegramStatus, getAdminTelegramStatus,
@@ -46,15 +47,22 @@ export default function DashboardScreen() {
const loadStats = useCallback(async () => { const loadStats = useCallback(async () => {
try { try {
const [allCmd, pending, enRoute, completed, clients, livreurs] = const [allCmd, pending, enRoute, completed, userCounts, livreurs] =
await Promise.all([ await Promise.all([
getAllCommands().then((r) => r.count), getAllCommands().then((r) => r.count),
getCommandCountByStatus("pending"), getCommandCountByStatus("pending"),
getCommandCountByStatus("en_route"), getCommandCountByStatus("en_route"),
getCommandCountByStatus("approved"), getCommandCountByStatus("approved"),
getAllClients(0, 1) // Totaux globaux (toute la base) : on ne charge qu'1 user,
.then((r) => r.total) // seuls les compteurs nous intéressent.
.catch(() => 0), getAllUsers(0, 1)
.then(async (r) => ({
all: r.counts?.all ?? r.total,
client:
r.counts?.client ??
(await getAllClients(0, 1)).total,
}))
.catch(() => ({ all: 0, client: 0 })),
getAvailableDeliveryPersons() getAvailableDeliveryPersons()
.then((r) => r.count) .then((r) => r.count)
.catch(() => 0), .catch(() => 0),
@@ -85,9 +93,15 @@ export default function DashboardScreen() {
icon: "checkmark-circle-outline", icon: "checkmark-circle-outline",
color: colors.success, color: colors.success,
}, },
{
label: "Utilisateurs",
value: userCounts.all,
icon: "person-outline",
color: colors.accent,
},
{ {
label: "Clients", label: "Clients",
value: clients, value: userCounts.client,
icon: "people-outline", icon: "people-outline",
color: colors.accentLight, color: colors.accentLight,
}, },
@@ -36,7 +36,11 @@ import {
subtractClientPoints, subtractClientPoints,
getLivreurLoginHistory, getLivreurLoginHistory,
} from "../../api/api_admin"; } from "../../api/api_admin";
import type { CancelledOrder, LoginHistoryWeek } from "../../api/api_admin"; import type {
CancelledOrder,
LoginHistoryWeek,
UserCounts,
} from "../../api/api_admin";
import type { ClientResponse } from "../../api/types"; import type { ClientResponse } from "../../api/types";
import LoadingSpinner from "../../components/ui/LoadingSpinner"; import LoadingSpinner from "../../components/ui/LoadingSpinner";
import Card from "../../components/ui/Card"; import Card from "../../components/ui/Card";
@@ -144,6 +148,9 @@ export default function UsersScreen() {
const [usersHasMore, setUsersHasMore] = useState(true); const [usersHasMore, setUsersHasMore] = useState(true);
const [clientsHasMore, setClientsHasMore] = useState(true); const [clientsHasMore, setClientsHasMore] = useState(true);
const [loadingMore, setLoadingMore] = useState(false); const [loadingMore, setLoadingMore] = useState(false);
// Totaux globaux renvoyés par le backend (toute la base, pas seulement
// les pages déjà chargées).
const [counts, setCounts] = useState<UserCounts | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false); const [refreshing, setRefreshing] = useState(false);
const [poolNames, setPoolNames] = useState<string[]>([]); const [poolNames, setPoolNames] = useState<string[]>([]);
@@ -264,6 +271,7 @@ export default function UsersScreen() {
]); ]);
setUsers(usersRes.items); setUsers(usersRes.items);
setClients(clientsRes.items); setClients(clientsRes.items);
if (usersRes.counts) setCounts(usersRes.counts);
setUsersHasMore(usersRes.hasMore); setUsersHasMore(usersRes.hasMore);
setClientsHasMore(clientsRes.hasMore); setClientsHasMore(clientsRes.hasMore);
if (settingsRes.success && settingsRes.settings) { if (settingsRes.success && settingsRes.settings) {
@@ -402,15 +410,21 @@ export default function UsersScreen() {
return merged; return merged;
}, [allMergedUsers, filter, search]); }, [allMergedUsers, filter, search]);
// Stats // Stats : totaux globaux du backend. Repli sur les données chargées
// uniquement si le backend n'a pas renvoyé les totaux.
const totalAll = counts?.all ?? allMergedUsers.length;
const totalClients = const totalClients =
users.filter((u) => u.role === "client").length || clients.length; counts?.client ??
const totalLivreurs = users.filter((u) => u.role === "livreur").length; (users.filter((u) => u.role === "client").length || clients.length);
const totalCabines = users.filter((u) => u.role === "cabine").length; const totalLivreurs =
const totalAdmins = users.filter((u) => u.role === "admin").length; counts?.livreur ?? users.filter((u) => u.role === "livreur").length;
const totalCabines =
counts?.cabine ?? users.filter((u) => u.role === "cabine").length;
const totalAdmins =
counts?.admin ?? users.filter((u) => u.role === "admin").length;
const getCountForFilter = (f: RoleFilter) => { const getCountForFilter = (f: RoleFilter) => {
if (f === "all") return mergedUsers.length; if (f === "all") return totalAll;
if (f === "client") return totalClients; if (f === "client") return totalClients;
if (f === "livreur") return totalLivreurs; if (f === "livreur") return totalLivreurs;
if (f === "cabine") return totalCabines; if (f === "cabine") return totalCabines;
@@ -933,6 +947,7 @@ export default function UsersScreen() {
const freshUsers = await getAllUsers(0, PAGE_SIZE); const freshUsers = await getAllUsers(0, PAGE_SIZE);
setUsers(freshUsers.items); setUsers(freshUsers.items);
setUsersHasMore(freshUsers.hasMore); setUsersHasMore(freshUsers.hasMore);
if (freshUsers.counts) setCounts(freshUsers.counts);
if ( if (
freshUsers.items.find( freshUsers.items.find(
(u) => u.username === usernameToCreate, (u) => u.username === usernameToCreate,