Merge pull request #503 from R0m1k3/1.1

Improve error handling and logging for Excel export functionality
This commit is contained in:
LogiFlow authored and GitHub committed 2025-11-04 13:06:17 +01:00
commit 0f925a2664
3 files changed
+225 -2

No files matched your search

@@ -0,0 +1,207 @@
Lines
100
Actions
{
id: 20,
title: 'DLC',
content: 'Attention des DLC sont en expiré bientôt ou expiré, il faut s en occuper',
type: 'success',
storeId: 2,
createdBy: 'admin',
createdAt: 2025-09-24T11:26:13.521Z
},
{
id: 17,
title: 'Module Avoir',
content: "Le module d'avoir est en place",
type: 'error',
storeId: 1,
createdBy: 'admin',
createdAt: 2025-09-09T07:47:47.650Z
},
{
id: 16,
title: 'Mise à jour Prix',
content: 'Merci de mettre vos prix a jour tous les matins, certain magasin ne le font pas.',
type: 'success',
storeId: null,
createdBy: 'admin',
createdAt: 2025-08-18T10:45:08.585Z
},
{
id: 8,
title: 'Bon de Livraison',
content: 'Lorsque vous rentrez un numéro de bon de livraison, faite le a l identique, même les majuscules. Pour My candy Shop, prendre le numéro de commande.',
type: 'info',
storeId: null,
createdBy: 'admin_local',
createdAt: 2025-08-07T11:04:38.123Z
}
]
🔍 [PRODUCTION] Looking for user with username: admin
🔍 [PRODUCTION] Looking for user with username: admin
🔍 [PRODUCTION] Looking for user with username: admin
🔍 [PRODUCTION] Looking for user with username: admin_local
🔍 [PRODUCTION] Raw messages from DB: 4 items: [
{
id: 20,
title: 'DLC',
content: 'Attention des DLC sont en expiré bientôt ou expiré, il faut s en occuper',
type: 'success',
storeId: 2,
createdBy: 'admin',
createdAt: 2025-09-24T11:26:13.521Z
},
{
id: 17,
title: 'Module Avoir',
content: "Le module d'avoir est en place",
type: 'error',
storeId: 1,
createdBy: 'admin',
createdAt: 2025-09-09T07:47:47.650Z
},
{
id: 16,
title: 'Mise à jour Prix',
content: 'Merci de mettre vos prix a jour tous les matins, certain magasin ne le font pas.',
type: 'success',
storeId: null,
createdBy: 'admin',
createdAt: 2025-08-18T10:45:08.585Z
},
{
id: 8,
title: 'Bon de Livraison',
content: 'Lorsque vous rentrez un numéro de bon de livraison, faite le a l identique, même les majuscules. Pour My candy Shop, prendre le numéro de commande.',
type: 'info',
storeId: null,
createdBy: 'admin_local',
createdAt: 2025-08-07T11:04:38.123Z
}
]
🔍 [PRODUCTION] Looking for user with username: admin
🔍 [PRODUCTION] Looking for user with username: admin
🔍 [PRODUCTION] Looking for user with username: admin
🔍 [PRODUCTION] Looking for user with username: admin_local
🔍 [PRODUCTION] User search result: Found
🔍 [PRODUCTION] User search result: Found
🔍 [PRODUCTION] User search result: Found
🔍 [PRODUCTION] User search result: Found
🔍 [PRODUCTION] User search result: Not found
🔍 [PRODUCTION] User search result: Not found
❌ [PRODUCTION] User not found with username: admin_local
❌ [PRODUCTION] User not found with username: admin_local
🎯 [PRODUCTION] Found announcements: 4
🔍 [PRODUCTION] User search result: Found
🔍 [PRODUCTION] User search result: Found
GET /api/announcements 304 in 29ms
🎯 [PRODUCTION] Found announcements: 4
GET /api/announcements 304 in 31ms
GET /api/dlc-products 200 in 31ms
GET /api/groups 200 in 5ms
HEAD /api/health 200 in 1ms
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+18 -2
View File
@@ -503,18 +503,25 @@ export async function registerRoutes(app: Express): Promise<Server> {
// Route pour exporter l'échéancier vers Excel
app.post('/api/payment-schedule/export', isAuthenticated, async (req: any, res) => {
try {
console.log('📊 [EXPORT] Début de l\'export Excel');
const userId = req.user?.claims?.sub || req.user?.id;
if (!userId) {
console.error('❌ [EXPORT] Utilisateur non authentifié');
return res.status(401).json({ error: 'Utilisateur non authentifié' });
}
const user = await storage.getUser(userId);
console.log(`🔍 [EXPORT] Utilisateur: ${user?.username} (${user?.role})`);
if (!user || (user.role !== 'admin' && user.role !== 'directeur')) {
console.error('❌ [EXPORT] Accès refusé');
return res.status(403).json({ error: 'Accès refusé - Admin ou Directeur uniquement' });
}
// Récupérer les paramètres d'export
const { groupId, month, paymentMethods, includeHT, includeTTC } = req.body;
console.log('📋 [EXPORT] Paramètres:', { groupId, month, paymentMethods, includeHT, includeTTC });
// Validation
const groupIdSchema = z.coerce.number().int().positive();
@@ -583,8 +590,11 @@ export async function registerRoutes(app: Express): Promise<Server> {
.sort((a: any, b: any) => a.dueDate.getTime() - b.dueDate.getTime());
// Générer le fichier Excel
console.log('📦 [EXPORT] Import du module xlsx...');
const XLSX = await import('xlsx');
console.log('✅ [EXPORT] Module xlsx importé avec succès');
const workbook = XLSX.utils.book_new();
console.log('📄 [EXPORT] Workbook créé');
// Préparer les données pour Excel
const headers = ['Date d\'échéance', 'Fournisseur', 'Facture', 'Mode de paiement'];
@@ -644,8 +654,14 @@ export async function registerRoutes(app: Express): Promise<Server> {
console.log(`📊 Export Excel généré: ${schedules.length} échéances pour ${group.name}`);
} catch (error: any) {
console.error('❌ Erreur export Excel:', error);
res.status(500).json({ error: 'Erreur lors de l\'export', details: error.message });
console.error('❌ [EXPORT] Erreur export Excel:', error);
console.error('❌ [EXPORT] Message:', error.message);
console.error('❌ [EXPORT] Stack:', error.stack);
res.status(500).json({
error: 'Erreur lors de l\'export',
details: error.message,
stack: process.env.NODE_ENV === 'development' ? error.stack : undefined
});
}
});