Rust discount function (one automatic discount evaluating all offers in priority order, parity with the Odoo engine), React Router admin with Polaris, theme app extension and app proxy pages, webhooks incl. GDPR, managed-pricing limits, and a Docker Compose stack (Postgres + Caddy HTTPS) for a single VPS. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22 lines
1004 B
TypeScript
22 lines
1004 B
TypeScript
import type { ActionFunctionArgs } from "react-router";
|
|
import { authenticate } from "../shopify.server";
|
|
import db from "../db.server";
|
|
import { DISCOUNT_TITLE, monthKey } from "../lib/publish.server";
|
|
import { recordOrder, type OrderPayload } from "../lib/orders.server";
|
|
|
|
export const action = async ({ request }: ActionFunctionArgs) => {
|
|
const { shop, payload } = await authenticate.webhook(request);
|
|
const row = await db.shop.findUnique({ where: { domain: shop } });
|
|
if (!row || row.uninstalledAt) return new Response();
|
|
const offers = await db.offer.findMany({ where: { shopId: row.id }, select: { id: true, name: true } });
|
|
const result = await recordOrder(row.id, payload as OrderPayload, offers, DISCOUNT_TITLE);
|
|
if (result.hasBundle && result.isNew) {
|
|
const key = monthKey();
|
|
await db.shop.update({
|
|
where: { id: row.id },
|
|
data: row.monthKey === key ? { monthOrders: { increment: 1 } } : { monthKey: key, monthOrders: 1 },
|
|
});
|
|
}
|
|
return new Response();
|
|
};
|