From 35b4dddb1b539c80d27b1f30bb6d33160ed4c951 Mon Sep 17 00:00:00 2001 From: Anthony Ettinger Date: Wed, 21 Oct 2026 13:42:45 +0000 Subject: [PATCH] fix(stores): bind today's date instead of date('now') for text expiry_date Postgres has no text >= date operator, so /stores/ 404'd and /api/stores/ returned 500. expiry_date is stored as TEXT 'YYYY-MM-DD' (and sometimes ''), so compare against a bound string in the same format. Co-Authored-By: Claude Opus 5.5 --- apps/web/app/api/stores/[slug]/route.ts | 5 ++++- apps/web/app/stores/[slug]/page.tsx | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/web/app/api/stores/[slug]/route.ts b/apps/web/app/api/stores/[slug]/route.ts index 35f2946..52567d3 100644 --- a/apps/web/app/api/stores/[slug]/route.ts +++ b/apps/web/app/api/stores/[slug]/route.ts @@ -10,9 +10,12 @@ export async function GET(_req: NextRequest, { params }: { params: Promise<{ slu if (!stores.length) return NextResponse.json({ error: 'Not found' }, { status: 404 }); const store = stores[0]; + // expiry_date is TEXT 'YYYY-MM-DD'; compare against a bound string, not date('now') + // (Postgres has no text >= date operator). + const today = new Date().toISOString().slice(0, 10); const coupons = await db.sql` SELECT * FROM coupons WHERE store_id = ${store.id} - AND (expiry_date IS NULL OR expiry_date = '' OR expiry_date >= date('now')) + AND (expiry_date IS NULL OR expiry_date = '' OR expiry_date >= ${today}) ORDER BY votes DESC, created_at DESC `; return NextResponse.json({ store, coupons }); diff --git a/apps/web/app/stores/[slug]/page.tsx b/apps/web/app/stores/[slug]/page.tsx index e03ddde..40a4058 100644 --- a/apps/web/app/stores/[slug]/page.tsx +++ b/apps/web/app/stores/[slug]/page.tsx @@ -16,9 +16,12 @@ const getStore = cache(async (slug: string): Promise<{ store: Store; coupons: Co const stores = await db.sql`SELECT * FROM stores WHERE slug = ${slug}`; if (!stores.length) return null; const store = stores[0]; + // expiry_date is TEXT 'YYYY-MM-DD'; compare against a bound string, not date('now') + // (Postgres has no text >= date operator). + const today = new Date().toISOString().slice(0, 10); const coupons = await db.sql` SELECT * FROM coupons WHERE store_id = ${store.id} - AND (expiry_date IS NULL OR expiry_date = '' OR expiry_date >= date('now')) + AND (expiry_date IS NULL OR expiry_date = '' OR expiry_date >= ${today}) ORDER BY votes DESC, created_at DESC `; return { store, coupons };