MCPcopy Create free account
hub / github.com/WebDevSimplified/course-platform / insertPurchase

Function insertPurchase

src/features/purchases/db/purchases.ts:6–28  ·  view source on GitHub ↗
(
  data: typeof PurchaseTable.$inferInsert,
  trx: Omit<typeof db, "$client"> = db
)

Source from the content-addressed store, hash-verified

4import { eq } from "drizzle-orm"
5
6export async function insertPurchase(
7 data: typeof PurchaseTable.$inferInsert,
8 trx: Omit<typeof db, "$client"> = db
9) {
10 const details = data.productDetails
11
12 const [newPurchase] = await trx
13 .insert(PurchaseTable)
14 .values({
15 ...data,
16 productDetails: {
17 name: details.name,
18 description: details.description,
19 imageUrl: details.imageUrl,
20 },
21 })
22 .onConflictDoNothing()
23 .returning()
24
25 if (newPurchase != null) revalidatePurchaseCache(newPurchase)
26
27 return newPurchase
28}
29
30export async function updatePurchase(
31 id: string,

Callers 1

processStripeCheckoutFunction · 0.90

Calls 1

revalidatePurchaseCacheFunction · 0.90

Tested by

no test coverage detected