import db from "../db.server"; export async function findSuccessfulPush(shop: string, orderId: string, activityId: number) { const record = await db.activityPushIdempotency.findUnique({ where: { shop_orderId_activityId: { shop, orderId, activityId: activityId.toString(), }, }, }); if (!record) { return null; } return { eventId: record.eventId, redirectUrl: record.redirectUrl, }; } export async function recordSuccessfulPush(entry: { shop: string; orderId: string; activityId: number; eventType: "order_end"; eventId: string; redirectUrl: string; buttonText: string; }) { await db.activityPushIdempotency.upsert({ where: { shop_orderId_activityId: { shop: entry.shop, orderId: entry.orderId, activityId: entry.activityId.toString(), }, }, update: { eventId: entry.eventId, redirectUrl: entry.redirectUrl, buttonText: entry.buttonText, pushedAt: new Date(), }, create: { shop: entry.shop, orderId: entry.orderId, activityId: entry.activityId.toString(), eventType: entry.eventType, eventId: entry.eventId, redirectUrl: entry.redirectUrl, buttonText: entry.buttonText, }, }); }