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
This commit is contained in:
michaelschal committed 2025-08-13 12:18:01 +00:00
1 parent 5259e2b2cd
commit a9c2b4ffb9
2 files changed
+13 -16

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@
# https://curl.se/docs/http-cookies.html # https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk. # 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
+12 -15
View File
@@ -613,12 +613,12 @@ export class DatabaseStorage implements IStorage {
// Construire les conditions pour le filtrage par groupe // Construire les conditions pour le filtrage par groupe
let ordersWhereCondition = and( let ordersWhereCondition = and(
gte(orders.plannedDate, new Date(startDate)), gte(orders.plannedDate, startDate),
lt(orders.plannedDate, new Date(endDate)) lt(orders.plannedDate, endDate)
); );
let deliveriesWhereCondition = and( let deliveriesWhereCondition = and(
gte(deliveries.plannedDate, new Date(startDate)), gte(deliveries.scheduledDate, startDate),
lt(deliveries.plannedDate, new Date(endDate)) lt(deliveries.scheduledDate, endDate)
); );
// Ajouter le filtre par groupe si spécifié // Ajouter le filtre par groupe si spécifié
@@ -640,12 +640,9 @@ export class DatabaseStorage implements IStorage {
.where(deliveriesWhereCondition); .where(deliveriesWhereCondition);
// Commandes en attente (sans date de livraison ou pas encore livrées) // Commandes en attente (sans date de livraison ou pas encore livrées)
let pendingWhereCondition = or( let pendingWhereCondition = eq(orders.status, 'pending');
isNull(orders.plannedDate),
eq(orders.status, 'pending')
);
if (groupIds && groupIds.length > 0) { 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 const pendingResult = await db
@@ -658,12 +655,12 @@ export class DatabaseStorage implements IStorage {
.select({ .select({
totalPalettes: sql<number>`COALESCE(SUM(CAST(${deliveries.quantity} as INTEGER)), 0)`, totalPalettes: sql<number>`COALESCE(SUM(CAST(${deliveries.quantity} as INTEGER)), 0)`,
totalPackages: sql<number>`COALESCE(COUNT(*), 0)`, totalPackages: sql<number>`COALESCE(COUNT(*), 0)`,
avgDelay: sql<number>`COALESCE(AVG(EXTRACT(DAY FROM (${deliveries.actualDate} - ${deliveries.plannedDate}))), 0)` avgDelay: sql<number>`COALESCE(AVG(EXTRACT(DAY FROM (${deliveries.deliveredDate} - ${deliveries.scheduledDate}))), 0)`
}) })
.from(deliveries) .from(deliveries)
.where(and( .where(and(
deliveriesWhereCondition, deliveriesWhereCondition,
isNotNull(deliveries.actualDate) isNotNull(deliveries.deliveredDate)
)); ));
const ordersCount = Number(ordersResult[0]?.count || 0); const ordersCount = Number(ordersResult[0]?.count || 0);
@@ -743,8 +740,8 @@ export class DatabaseStorage implements IStorage {
return results.map((publicity: any) => ({ return results.map((publicity: any) => ({
...publicity, ...publicity,
participations: participations participations: participations
.filter((p) => p.publicityId === publicity.id) .filter((p: any) => p.publicityId === publicity.id)
.map((p) => ({ .map((p: any) => ({
publicityId: p.publicityId, publicityId: p.publicityId,
groupId: p.groupId, groupId: p.groupId,
group: p.group!, group: p.group!,
@@ -768,7 +765,7 @@ export class DatabaseStorage implements IStorage {
return { return {
...publicity, ...publicity,
participations: participations.map(p => ({ participations: participations.map((p: any) => ({
publicityId: p.publicityId, publicityId: p.publicityId,
groupId: p.groupId, groupId: p.groupId,
group: p.group!, group: p.group!,
@@ -1015,7 +1012,7 @@ export class MemStorage implements IStorage {
lastName: userData.lastName || null, lastName: userData.lastName || null,
profileImageUrl: userData.profileImageUrl || null, profileImageUrl: userData.profileImageUrl || null,
password: userData.password || null, password: userData.password || null,
role: userData.role, role: userData.role || 'user',
passwordChanged: userData.passwordChanged || false, passwordChanged: userData.passwordChanged || false,
createdAt: existingUser?.createdAt || new Date(), createdAt: existingUser?.createdAt || new Date(),
updatedAt: new Date(), updatedAt: new Date(),