Merge pull request #316 from R0m1k3/1.1

Improve product expiry date filtering and supplier data retrieval
This commit is contained in:
LogiFlow authored and GitHub committed 2025-09-02 10:47:40 +02:00
commit 33a588e630
4 files changed
+9 -6

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+1 -1
View File
@@ -216,7 +216,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
// Filter suppliers for DLC enabled only if requested // Filter suppliers for DLC enabled only if requested
if (dlcFilter) { if (dlcFilter) {
const dlcSuppliers = suppliers.filter(supplier => supplier.dlcEnabled === true); const dlcSuppliers = suppliers.filter(supplier => supplier.hasDlc === true);
res.json(dlcSuppliers); res.json(dlcSuppliers);
} else { } else {
res.json(suppliers); res.json(suppliers);
+8 -5
View File
@@ -68,7 +68,7 @@ import {
type InsertWeatherSettings, type InsertWeatherSettings,
} from "@shared/schema"; } from "@shared/schema";
import { db } from "./db"; import { db } from "./db";
import { eq, and, inArray, desc, sql, gte, lte, lt, or, isNull, isNotNull, asc } from "drizzle-orm"; import { eq, and, inArray, desc, sql, gte, lte, lt, gt, or, isNull, isNotNull, asc, ne } from "drizzle-orm";
import { getAnnouncementStorage } from "./announcementStorage"; import { getAnnouncementStorage } from "./announcementStorage";
@@ -1511,15 +1511,17 @@ export class DatabaseStorage implements IStorage {
// Handle dynamic status filtering based on expiry date calculation // Handle dynamic status filtering based on expiry date calculation
if (filters.status && filters.status !== 'all') { if (filters.status && filters.status !== 'all') {
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); // Set to start of day for accurate comparison
if (filters.status === 'expires_soon') { if (filters.status === 'expires_soon') {
// Products expiring within 15 days but not expired yet // Products expiring within 15 days but not expired yet
const in15Days = new Date(); const in15Days = new Date();
in15Days.setDate(today.getDate() + 15); in15Days.setDate(today.getDate() + 15);
in15Days.setHours(23, 59, 59, 999); // End of day
conditions.push( conditions.push(
and( and(
sql`${dlcProducts.expiryDate} > ${today}`, gt(dlcProducts.expiryDate, today),
sql`${dlcProducts.expiryDate} <= ${in15Days}`, lte(dlcProducts.expiryDate, in15Days),
ne(dlcProducts.status, 'valides') ne(dlcProducts.status, 'valides')
) )
); );
@@ -1527,7 +1529,7 @@ export class DatabaseStorage implements IStorage {
// Products already expired // Products already expired
conditions.push( conditions.push(
and( and(
sql`${dlcProducts.expiryDate} <= ${today}`, lte(dlcProducts.expiryDate, today),
ne(dlcProducts.status, 'valides') ne(dlcProducts.status, 'valides')
) )
); );
@@ -1535,9 +1537,10 @@ export class DatabaseStorage implements IStorage {
// Products active (more than 15 days until expiry) // Products active (more than 15 days until expiry)
const in15Days = new Date(); const in15Days = new Date();
in15Days.setDate(today.getDate() + 15); in15Days.setDate(today.getDate() + 15);
in15Days.setHours(23, 59, 59, 999);
conditions.push( conditions.push(
and( and(
sql`${dlcProducts.expiryDate} > ${in15Days}`, gt(dlcProducts.expiryDate, in15Days),
ne(dlcProducts.status, 'valides') ne(dlcProducts.status, 'valides')
) )
); );