diff --git a/attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt b/attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt new file mode 100644 index 0000000..f4c4e12 --- /dev/null +++ b/attached_assets/Pasted--getUserWithGroups-called-for-user-admin-local-Querying-user-groups-for-user-adm-1754945126235_1754945126235.txt @@ -0,0 +1,202 @@ + + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +Deliveries API called with: { + + startDate: undefined, + + endDate: undefined, + + storeId: undefined, + + withBL: undefined, + + userRole: 'admin' + +} + +Admin filtering deliveries with groupIds: undefined + +Fetching all deliveries + +Deliveries returned: 80 items + +GET /api/deliveries 304 in 44ms + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +📄 SPA: Serving index.html for /[object%20Object] + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +📄 SPA: Serving index.html for /[object%20Object] + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +📄 SPA: Serving index.html for /[object%20Object] + +🔍 getUserWithGroups called for user: admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +🔍 getUserWithGroups called for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +Orders API called with: { + + startDate: '2025-08-01', + + endDate: '2025-08-31', + + storeId: '1', + + userRole: 'admin' + +} + +Admin filtering with groupIds: [ 1 ] + +Fetching orders by date range: 2025-08-01 to 2025-08-31 + +🔍 Querying user_groups for user: admin_local + +🔍 Found 0 group assignments for user admin_local + +🔍 Raw query result: [] + +✅ Processed 0 groups for user admin_local + +Deliveries API called with: { + + startDate: '2025-08-01', + + endDate: '2025-08-31', + + storeId: '1', + + withBL: undefined, + + userRole: 'admin' + +} + +Admin filtering deliveries with groupIds: [ 1 ] + +Fetching deliveries by date range: 2025-08-01 to 2025-08-31 + +Orders returned: 9 items + +GET /api/orders 304 in 23ms + +Deliveries returned: 20 items + +GET /api/deliveries 304 in 36ms + diff --git a/server/routes.ts b/server/routes.ts index 70fa5b5..eb21026 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -690,6 +690,18 @@ export async function registerRoutes(app: Express): Promise { const data = insertDeliverySchema.partial().parse(req.body); const updatedDelivery = await storage.updateDelivery(id, data); + + // SYNCHRONISATION AUTOMATIQUE : Si livraison devient "delivered", marquer la commande associée comme "delivered" + if (data.status === 'delivered' && updatedDelivery.orderId) { + try { + console.log(`🔄 Auto-sync: Delivery #${id} marked as delivered, updating order #${updatedDelivery.orderId}`); + await storage.updateOrder(updatedDelivery.orderId, { status: 'delivered' }); + console.log(`✅ Auto-sync: Order #${updatedDelivery.orderId} automatically marked as delivered`); + } catch (error) { + console.error(`❌ Auto-sync failed for order #${updatedDelivery.orderId}:`, error); + } + } + res.json(updatedDelivery); } catch (error) { console.error("Error updating delivery:", error); @@ -828,6 +840,18 @@ export async function registerRoutes(app: Express): Promise { } await storage.validateDelivery(id, blData); + + // SYNCHRONISATION AUTOMATIQUE : Quand validation, marquer la commande associée comme "delivered" + if (delivery.orderId) { + try { + console.log(`🔄 Auto-sync: Delivery #${id} validated, updating order #${delivery.orderId} to delivered`); + await storage.updateOrder(delivery.orderId, { status: 'delivered' }); + console.log(`✅ Auto-sync: Order #${delivery.orderId} automatically marked as delivered`); + } catch (error) { + console.error(`❌ Auto-sync failed for order #${delivery.orderId}:`, error); + } + } + res.json({ message: "Delivery validated successfully" }); } catch (error) { console.error("Error validating delivery:", error);