The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Enhance bounty update logic to prevent changes to performance conditions if submissions exist
Kiran K79cb6749d950
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.tsindex ec18678bea..fece6309b1 100644--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts@@ -7,12 +7,14 @@ import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-progrimport { parseRequestBody } from "@/lib/api/utils";import { withWorkspace } from "@/lib/auth";import { qstash } from "@/lib/cron";+import { WorkflowCondition } from "@/lib/types";import { sendWorkspaceWebhook } from "@/lib/webhook/publish";import {BountySchema,BountySchemaExtended,updateBountySchema,} from "@/lib/zod/schemas/bounties";+import { WORKFLOW_ATTRIBUTE_LABELS } from "@/lib/zod/schemas/workflows";import { prisma } from "@dub/prisma";import { APP_DOMAIN_WITH_NGROK, arrayEqual } from "@dub/utils";import { PartnerGroup, Prisma } from "@prisma/client";@@ -78,6 +80,12 @@ export const PATCH = withWorkspace(},include: {groups: true,+ workflow: true,+ _count: {+ select: {+ submissions: true,+ },+ },},});@@ -114,6 +122,24 @@ export const PATCH = withWorkspace(});}+ // Prevent updates if `performanceCondition.attribute` differs from the current value if there are existing submissions+ if (performanceCondition && bounty.workflow) {+ const submissionCount = bounty._count.submissions;+ const currentCondition = bounty.workflow+ .triggerConditions?.[0] as WorkflowCondition;++ if (+ currentCondition &&+ currentCondition.attribute !== performanceCondition.attribute &&+ submissionCount > 0+ ) {+ throw new DubApiError({+ code: "bad_request",+ message: `You cannot change the performance condition from "${WORKFLOW_ATTRIBUTE_LABELS[currentCondition.attribute]}" to "${WORKFLOW_ATTRIBUTE_LABELS[performanceCondition.attribute]}" because the bounty has submissions.`,+ });+ }+ }+// Bounty namelet bountyName = name;diff --git a/apps/web/ui/partners/bounties/bounty-logic.tsx b/apps/web/ui/partners/bounties/bounty-logic.tsxindex 78e0ee727a..8ebaf9e268 100644--- a/apps/web/ui/partners/bounties/bounty-logic.tsx+++ b/apps/web/ui/partners/bounties/bounty-logic.tsx@@ -23,10 +23,9 @@ const WORKFLOW_ATTRIBUTE_LABELS: Record<WorkflowConditionAttribute, string> = {export function BountyLogic({ className }: { className?: string }) {const { control, watch } = useAddEditBountyForm();- const [attribute, value, currentStatsOnly] = watch([+ const [attribute, value] = watch(["performanceCondition.attribute","performanceCondition.value",- "currentStatsOnly",]);return (