Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/web/app/api/stores/[slug]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
5 changes: 4 additions & 1 deletion apps/web/app/stores/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
Loading