The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Use partner eligibility helpers in complete bounty workflows.
Kiran K93d013decf65
diff --git a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.tsindex 49b73ed0ef..1860343ce8 100644--- a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts+++ b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts@@ -1,4 +1,8 @@import { evaluateWorkflowConditions } from "@/lib/api/workflows/evaluate-workflow-conditions";+import {+ getEffectiveBountyPeriod,+ isPartnerEligibleForBounty,+} from "@/lib/bounty/api/bounty-availability";import { prisma } from "@/lib/prisma";import { WorkflowConditionAttribute, WorkflowContext } from "@/lib/types";import { WORKFLOW_ACTION_TYPES } from "@/lib/zod/schemas/workflows";@@ -37,8 +41,9 @@ export const executeCompleteBountyWorkflow = async ({}const { bountyId } = action.data;- const { identity, metrics } = context;- const { partnerId, groupId, customerId, customerFirstSaleAt } = identity;+ const { identity, metrics, programEnrollment } = context;+ const { customerId, customerFirstSaleAt } = identity;+ const { partnerId, groupId } = programEnrollment;if (!groupId) {console.error("Partner groupId not set in the context.");@@ -51,11 +56,24 @@ export const executeCompleteBountyWorkflow = async ({id: bountyId,},include: {- program: true,- groups: true,+ program: {+ select: {+ id: true,+ name: true,+ slug: true,+ supportEmail: true,+ defaultGroupId: true,+ },+ },+ groups: {+ select: {+ groupId: true,+ },+ },submissions: {- where: {- partnerId,+ select: {+ id: true,+ status: true,},},},@@ -77,30 +95,19 @@ export const executeCompleteBountyWorkflow = async ({return;}- const now = new Date();-- // Check if bounty is active- if (- (bounty.startsAt && bounty.startsAt > now) ||- (bounty.endsAt && bounty.endsAt < now) ||- bounty.archivedAt- ) {- console.log(`Bounty ${bounty.id} is no longer active.`);- return;- }+ const { submissions, program } = bounty;- const { groups, submissions } = bounty;-- // If the bounty is part of a group, check if the partner is in the group- if (groups.length > 0) {- const groupIds = groups.map(({ groupId }) => groupId);+ const isEligible = isPartnerEligibleForBounty({+ program,+ bounty,+ programEnrollment,+ });- if (!groupIds.includes(groupId)) {- console.log(- `Partner ${partnerId} is not eligible for bounty ${bounty.id} because they are not in any of the assigned groups. Partner's groupId: ${groupId}. Assigned groupIds: ${groupIds.join(", ")}.`,- );- return;- }+ if (!isEligible) {+ console.log(+ `Partner ${partnerId} is not eligible for bounty ${bounty.id}.`,+ );+ return;}if (submissions.length > 0) {@@ -118,11 +125,15 @@ export const executeCompleteBountyWorkflow = async ({}}+ const { startsAt } = getEffectiveBountyPeriod({+ programEnrollment,+ bounty,+ });+if (bounty.performanceScope === "new" &&customerFirstSaleAt &&- bounty.startsAt &&- customerFirstSaleAt < bounty.startsAt+ customerFirstSaleAt < startsAt) {console.log(`Bounty ${bounty.id} is for net-new revenue only and partner ${partnerId} referred customer ${customerId} before the bounty started, skipping...`,diff --git a/apps/web/lib/api/workflows/execute-workflows.ts b/apps/web/lib/api/workflows/execute-workflows.tsindex aa209ab8d0..975478a02e 100644--- a/apps/web/lib/api/workflows/execute-workflows.ts+++ b/apps/web/lib/api/workflows/execute-workflows.ts@@ -127,9 +127,7 @@ export async function executeWorkflows({programId,},},- select: {- partnerId: true,- groupId: true,+ include: {links: {select: {clicks: true,@@ -177,6 +175,7 @@ export async function executeWorkflows({aggregatePartnerLinksStats(programEnrollment.links);const workflowContext: WorkflowContext = {+ programEnrollment,trigger,reason,identity: {diff --git a/apps/web/lib/bounty/api/bounty-availability.ts b/apps/web/lib/bounty/api/bounty-availability.tsindex de10ac3a5f..35edd04832 100644--- a/apps/web/lib/bounty/api/bounty-availability.ts+++ b/apps/web/lib/bounty/api/bounty-availability.ts@@ -131,7 +131,7 @@ export function isPartnerEligibleForBounty({if (bountyGroupIds.length > 0 && !bountyGroupIds.includes(partnerGroupId)) {console.log(- `Partner doesn't belong to any of the bounty's ${bounty.id} groups.`,+ `Partner is not eligible for bounty ${bounty.id} because they are not in any of the assigned groups. Partner's groupId: ${partnerGroupId}. Assigned groupIds: ${bountyGroupIds.join(", ")}.`,);return false;}diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex 3e34281ea5..2d0d225e98 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -23,6 +23,7 @@ import {PartnerRole,PayoutStatus,Prisma,+ ProgramEnrollment,ProgramEnrollmentStatus,Project,SubmittedLead,@@ -864,6 +865,15 @@ export interface WorkflowContext {current?: PartnerMetrics;aggregated?: PartnerMetrics;};+ programEnrollment: Pick<+ ProgramEnrollment,+ | "groupId"+ | "createdAt"+ | "groupJoinedAt"+ | "partnerId"+ | "programId"+ | "status"+ >;}export type SubmittedLeadProps = z.infer<typeof submittedLeadSchema>;