UNPKG

@coursebuilder/core

Version:

Core package for Course Builder

67 lines (65 loc) 1.84 kB
import { z } from "./chunk-JLNB6NRA.js"; import { __name } from "./chunk-VLQXSCFN.js"; // src/lib/actions/transfer-purchase.ts import { v4 } from "uuid"; async function transferPurchase(request, cookies, options) { if (!options.adapter) throw new Error("Adapter not found"); if (request.headers?.["x-skill-secret"] !== process.env.SKILL_SECRET) { return { status: 401, body: "unauthorized" }; } const parsedTransferPurchaseOptions = z.object({ purchaseId: z.string(), targetUserEmail: z.string(), sourceUserId: z.string() }).safeParse(request.body); if (!parsedTransferPurchaseOptions.success) { return { status: 400, body: JSON.stringify({ error: parsedTransferPurchaseOptions.error }) }; } try { const transferPurchaseOptions = parsedTransferPurchaseOptions.data; let targetUser = await options.adapter.getUserByEmail(transferPurchaseOptions.targetUserEmail); if (!targetUser) { targetUser = await options.adapter.createUser({ id: v4(), email: transferPurchaseOptions.targetUserEmail, emailVerified: /* @__PURE__ */ new Date() }); } await options.adapter.transferPurchaseToUser({ sourceUserId: transferPurchaseOptions.sourceUserId, purchaseId: transferPurchaseOptions.purchaseId, targetUserId: targetUser.id }); const updatedPurchase = await options.adapter.getPurchase(transferPurchaseOptions.purchaseId); return { status: 200, body: JSON.stringify(updatedPurchase) }; } catch (e) { console.log("error", e); return { status: 500, body: JSON.stringify({ error: e.message }) }; } } __name(transferPurchase, "transferPurchase"); export { transferPurchase }; //# sourceMappingURL=chunk-W2PMM4NN.js.map