From a9c2b4ffb9ae889884ef75e27273d962eb7e1331 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Wed, 13 Aug 2025 12:18:01 +0000 Subject: [PATCH] Update date filtering and delivery calculations for improved performance Refactor date handling in DatabaseStorage to use direct date comparisons instead of new Date() objects, adjust pending order filtering, and correct calculations for average delivery delay. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7c468936-2a88-4686-ac0a-84921a45222d Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/7c468936-2a88-4686-ac0a-84921a45222d/oW0kTqb --- cookies.txt | 2 +- server/storage.ts | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cookies.txt b/cookies.txt index 7791439..c951897 100644 --- a/cookies.txt +++ b/cookies.txt @@ -2,4 +2,4 @@ # https://curl.se/docs/http-cookies.html # This file was generated by libcurl! Edit at your own risk. -#HttpOnly_localhost FALSE / FALSE 1755173643 connect.sid s%3ARJVevhpqKq9drfbbR46G-2Ll2WIWg2Es.qOQvBzSdDPOh9zhkIbeCCSRmumFEtIy1LT2pYBPaEck +#HttpOnly_localhost FALSE / FALSE 1755173847 connect.sid s%3ANh8VuEqk2J-ItTNJEGOkI2oMijs2phlk.d7750iTT0H6Yxgo2fS9Uglu%2F5iyGWhbnHDT4H50h7zU diff --git a/server/storage.ts b/server/storage.ts index 27f0951..99aa7c9 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -613,12 +613,12 @@ export class DatabaseStorage implements IStorage { // Construire les conditions pour le filtrage par groupe let ordersWhereCondition = and( - gte(orders.plannedDate, new Date(startDate)), - lt(orders.plannedDate, new Date(endDate)) + gte(orders.plannedDate, startDate), + lt(orders.plannedDate, endDate) ); let deliveriesWhereCondition = and( - gte(deliveries.plannedDate, new Date(startDate)), - lt(deliveries.plannedDate, new Date(endDate)) + gte(deliveries.scheduledDate, startDate), + lt(deliveries.scheduledDate, endDate) ); // Ajouter le filtre par groupe si spécifié @@ -640,12 +640,9 @@ export class DatabaseStorage implements IStorage { .where(deliveriesWhereCondition); // Commandes en attente (sans date de livraison ou pas encore livrées) - let pendingWhereCondition = or( - isNull(orders.plannedDate), - eq(orders.status, 'pending') - ); + let pendingWhereCondition = eq(orders.status, 'pending'); if (groupIds && groupIds.length > 0) { - pendingWhereCondition = and(pendingWhereCondition, inArray(orders.groupId, groupIds)); + pendingWhereCondition = and(pendingWhereCondition, inArray(orders.groupId, groupIds)) as any; } const pendingResult = await db @@ -658,12 +655,12 @@ export class DatabaseStorage implements IStorage { .select({ totalPalettes: sql`COALESCE(SUM(CAST(${deliveries.quantity} as INTEGER)), 0)`, totalPackages: sql`COALESCE(COUNT(*), 0)`, - avgDelay: sql`COALESCE(AVG(EXTRACT(DAY FROM (${deliveries.actualDate} - ${deliveries.plannedDate}))), 0)` + avgDelay: sql`COALESCE(AVG(EXTRACT(DAY FROM (${deliveries.deliveredDate} - ${deliveries.scheduledDate}))), 0)` }) .from(deliveries) .where(and( deliveriesWhereCondition, - isNotNull(deliveries.actualDate) + isNotNull(deliveries.deliveredDate) )); const ordersCount = Number(ordersResult[0]?.count || 0); @@ -743,8 +740,8 @@ export class DatabaseStorage implements IStorage { return results.map((publicity: any) => ({ ...publicity, participations: participations - .filter((p) => p.publicityId === publicity.id) - .map((p) => ({ + .filter((p: any) => p.publicityId === publicity.id) + .map((p: any) => ({ publicityId: p.publicityId, groupId: p.groupId, group: p.group!, @@ -768,7 +765,7 @@ export class DatabaseStorage implements IStorage { return { ...publicity, - participations: participations.map(p => ({ + participations: participations.map((p: any) => ({ publicityId: p.publicityId, groupId: p.groupId, group: p.group!, @@ -1015,7 +1012,7 @@ export class MemStorage implements IStorage { lastName: userData.lastName || null, profileImageUrl: userData.profileImageUrl || null, password: userData.password || null, - role: userData.role, + role: userData.role || 'user', passwordChanged: userData.passwordChanged || false, createdAt: existingUser?.createdAt || new Date(), updatedAt: new Date(),