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 import-campaign.ts

Steven Teyd2dedc6625b2
diff --git a/apps/web/lib/rewardful/import-campaign.ts b/apps/web/lib/rewardful/import-campaign.ts
index fd63cdfe6f..073cddafb8 100644
--- a/apps/web/lib/rewardful/import-campaign.ts
+++ b/apps/web/lib/rewardful/import-campaign.ts
@@ -6,7 +6,7 @@ import { RewardfulApi } from "./api";
import { rewardfulImporter } from "./importer";
export async function importCampaign({ programId }: { programId: string }) {
- const { workspaceId, rewards: defaultRewards } =
+ const { workspaceId, rewards: defaultSaleReward } =
await prisma.program.findUniqueOrThrow({
where: {
id: programId,
@@ -14,6 +14,7 @@ export async function importCampaign({ programId }: { programId: string }) {
include: {
rewards: {
where: {
+ event: EventType.sale,
default: true,
},
},
@@ -55,20 +56,16 @@ export async function importCampaign({ programId }: { programId: string }) {
});
if (!rewardFound) {
- const defaultSaleReward = defaultRewards.find(
- (reward) => reward.event === EventType.sale,
- );
-
const reward = await prisma.reward.create({
data: {
...newReward,
id: createId({ prefix: "rw_" }),
- default: !defaultSaleReward,
+ default: !defaultSaleReward.length,
},
});
// if there's no default reward, means that this is a newly imported program
- if (!defaultRewards.length) {
+ if (!defaultSaleReward.length) {
await prisma.program.update({
where: {
id: programId,