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
# 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
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<number>`COALESCE(SUM(CAST(${deliveries.quantity} as INTEGER)), 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)
.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(),