Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

fix discount user update

Steven Tey2e4b762b889f
diff --git a/apps/web/lib/actions/partners/update-discount.ts b/apps/web/lib/actions/partners/update-discount.ts
index 2b7fc6671d..ee5d48ceab 100644
--- a/apps/web/lib/actions/partners/update-discount.ts
+++ b/apps/web/lib/actions/partners/update-discount.ts
@@ -69,16 +69,32 @@ export const updateDiscountAction = authActionClient
});
if (partnerIds && partnerIds.length > 0) {
- await prisma.programEnrollment.updateMany({
- where: {
- programId,
- partnerId: {
- in: partnerIds,
+ await prisma.$transaction([
+ // assign discountId to partners in partnerIds
+ prisma.programEnrollment.updateMany({
+ where: {
+ programId,
+ partnerId: {
+ in: partnerIds,
+ },
},
- },
- data: {
- discountId,
- },
- });
+ data: {
+ discountId,
+ },
+ }),
+ // remove discountId from partners not in partnerIds
+ prisma.programEnrollment.updateMany({
+ where: {
+ programId,
+ partnerId: {
+ notIn: partnerIds,
+ },
+ discountId,
+ },
+ data: {
+ discountId: null,
+ },
+ }),
+ ]);
}
});