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.

Update delete-reward.ts

Kiran K2f2c9f2f8b3e
diff --git a/apps/web/lib/actions/partners/delete-reward.ts b/apps/web/lib/actions/partners/delete-reward.ts
index 791151e163..a4705f53b9 100644
--- a/apps/web/lib/actions/partners/delete-reward.ts
+++ b/apps/web/lib/actions/partners/delete-reward.ts
@@ -30,28 +30,25 @@ export const deleteRewardAction = authActionClient
const rewardIdColumn = REWARD_EVENT_COLUMN_MAPPING[reward.event];
await prisma.$transaction(async (tx) => {
- // 1. Find the default reward for the same event (if it exists)
- const defaultReward = await tx.reward.findFirst({
+ await tx.partnerGroup.update({
+ // @ts-ignore
where: {
- programId,
- event: reward.event,
- default: true,
+ [rewardIdColumn]: reward.id,
+ },
+ data: {
+ [rewardIdColumn]: null,
},
});
- // 2. Update current associations
await tx.programEnrollment.updateMany({
where: {
- programId,
[rewardIdColumn]: reward.id,
},
data: {
- // Replace the current reward with the default reward for the same event if it exists
- [rewardIdColumn]: defaultReward ? defaultReward.id : null,
+ [rewardIdColumn]: null,
},
});
- // 3. Finally, delete the current reward
await tx.reward.delete({
where: {
id: reward.id,