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>
29 lines
1.3 KiB
TypeScript
29 lines
1.3 KiB
TypeScript
// Shared loading for the app proxy pages. Public: never depends on a logged-in customer (brief §8).
|
|
import db from "../db.server";
|
|
import { offerInclude } from "./offers.server";
|
|
import { compile } from "./compile";
|
|
import { planOf } from "./plans";
|
|
|
|
export const PROXY_CACHE = "public, max-age=60";
|
|
|
|
export async function runningOffersForShop(domain: string, country: string | null) {
|
|
const shop = await db.shop.findUnique({ where: { domain } });
|
|
if (!shop || shop.uninstalledAt) return null;
|
|
const offers = await db.offer.findMany({ where: { shopId: shop.id, active: true, published: true }, include: offerInclude });
|
|
// Same selection as the discount function: running + allowed by the plan.
|
|
const result = compile(
|
|
{ planCode: shop.planCode, currency: shop.currency, timezone: shop.timezone, settings: shop.settings, monthOrders: 0 },
|
|
offers,
|
|
);
|
|
const included = new Set(result.included);
|
|
const running = offers
|
|
.filter((o) => included.has(o.id))
|
|
.filter((o) => !o.countries.length || (country && o.countries.includes(country)))
|
|
.sort((a, b) => result.included.indexOf(a.id) - result.included.indexOf(b.id));
|
|
return {
|
|
shop,
|
|
running,
|
|
ctx: { currency: shop.currency, timezone: shop.timezone, branding: planOf(shop.planCode).branding },
|
|
};
|
|
}
|