( data: typeof PurchaseTable.$inferInsert, trx: Omit<typeof db, "$client"> = db )
| 4 | import { eq } from "drizzle-orm" |
| 5 | |
| 6 | export 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 | |
| 30 | export async function updatePurchase( |
| 31 | id: string, |
no test coverage detected