datewise/app/lib/bookings-query.server.ts
metatroncubeswdev e56182e0e3 chore: initial Datewise app (rebranded from SlotSure prototype)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 20:06:49 -04:00

21 lines
1.2 KiB
TypeScript

import type { Prisma } from "@prisma/client";
/** Booking list filters shared by the list page and the CSV export. */
export function bookingWhere(shopId: string, sp: URLSearchParams, today: string): Prisma.BookingWhereInput {
const status = sp.get("status") ?? "upcoming";
const where: Prisma.BookingWhereInput = { shopId };
if (status === "review") where.OR = [{ status: "needs_review" }, { status: "confirmed", reviewReason: { not: null } }];
else if (status === "upcoming") Object.assign(where, { status: "confirmed", date: { gte: today } });
else if (status !== "all") where.status = status;
const method = sp.get("method");
if (method && method !== "all") where.method = method;
const loc = sp.get("location");
if (loc && loc !== "all") where.locationId = loc;
const from = sp.get("from");
const to = sp.get("to");
if (from || to) where.date = { ...(from ? { gte: from } : {}), ...(to ? { lte: to } : {}) };
const q = sp.get("q")?.trim();
if (q) where.AND = [{ OR: [{ orderName: { contains: q, mode: "insensitive" } }, { customerName: { contains: q, mode: "insensitive" } }, { customerEmail: { contains: q, mode: "insensitive" } }] }];
return where;
}