mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Update dashboard to display yearly delivery statistics
Introduce a new API endpoint '/api/stats/yearly' for fetching annual statistics and update the StatsPanel component to use this endpoint, changing the card title to "Statistiques de l'année" and the average delivery time label to "Délai commande → livraison". Replit-Commit-Author: Agent Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/9qfOTfC
This commit is contained in:
1 parent
d938db04ff
commit
6ba8919487
4 files changed
+209
-7
No files matched your search
@@ -2337,6 +2337,42 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
// Route pour les statistiques annuelles
|
||||
app.get('/api/stats/yearly', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
const user = await storage.getUserWithGroups(req.user.claims ? req.user.claims.sub : req.user.id);
|
||||
if (!user) {
|
||||
return res.status(404).json({ message: "User not found" });
|
||||
}
|
||||
|
||||
const { year, storeId } = req.query;
|
||||
const currentYear = year ? parseInt(year as string) : new Date().getFullYear();
|
||||
|
||||
let groupIds: number[] | undefined;
|
||||
|
||||
if (user.role === 'admin') {
|
||||
// Admin can view all stores or filter by selected store
|
||||
groupIds = storeId ? [parseInt(storeId as string)] : undefined;
|
||||
} else {
|
||||
// Non-admin users: filter by their assigned groups
|
||||
const userGroupIds = user.userGroups.map(ug => ug.groupId);
|
||||
|
||||
// If a specific store is selected and user has access, filter by it
|
||||
if (storeId && userGroupIds.includes(parseInt(storeId as string))) {
|
||||
groupIds = [parseInt(storeId as string)];
|
||||
} else {
|
||||
groupIds = userGroupIds;
|
||||
}
|
||||
}
|
||||
|
||||
const stats = await storage.getYearlyStats(currentYear, groupIds);
|
||||
res.json(stats);
|
||||
} catch (error) {
|
||||
console.error("Error fetching yearly stats:", error);
|
||||
res.status(500).json({ message: "Failed to fetch yearly statistics" });
|
||||
}
|
||||
});
|
||||
|
||||
// User-Group management routes (admin only)
|
||||
app.post('/api/users/:userId/groups', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user