import type { ActionFunctionArgs } from "@remix-run/node"; import { authenticate } from "../shopify.server"; import db from "../db.server"; import { writeCheckoutSnapshot } from "../services/checkout-snapshot.server"; // Marks the linked Booking cancelled, which frees its capacity for // getAvailability()/the hold endpoint's confirmedCount check on the next // request — see IMPLEMENTATION_PLAN.md §5.2. export const action = async ({ request }: ActionFunctionArgs) => { const { shop, topic, payload, admin } = await authenticate.webhook(request); console.log(`Received ${topic} webhook for ${shop}`); const order = payload as unknown as { admin_graphql_api_id: string }; await db.booking.updateMany({ where: { shopDomain: shop, orderId: order.admin_graphql_api_id }, data: { status: "cancelled" }, }); // Capacity just freed up — the checkout snapshot must reflect it so the // Validation Function stops blocking a slot that's now open again. if (admin) { await writeCheckoutSnapshot(admin, shop); } return new Response(); };