datewise/app/routes/webhooks.orders.create.tsx
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

20 lines
929 B
TypeScript

import type { ActionFunctionArgs } from "react-router";
import prisma from "../db.server";
import { authenticate } from "../shopify.server";
import { firstDelivery, handleOrderCreate, type OrderPayload } from "../services/orders.server";
export const action = async ({ request }: ActionFunctionArgs) => {
const { shop, topic, payload, admin, webhookId } = await authenticate.webhook(request);
const eventId = request.headers.get("x-shopify-event-id") ?? webhookId;
if (!(await firstDelivery(eventId, topic, shop))) return new Response();
try {
await handleOrderCreate(shop, payload as OrderPayload, admin);
} catch (e) {
console.error("orders/create failed", shop, e);
// Let Shopify retry; the idempotency row must not block the retry.
await prisma.processedWebhook.delete({ where: { id: eventId } }).catch(() => {});
return new Response("retry", { status: 500 });
}
return new Response();
};