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.

Align bounty period checks with partner eligibility helper

Kiran K9b5aa9e83c4b
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/sync-social-metrics/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/sync-social-metrics/route.ts
index 956b6d41c9..5ecb517532 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/sync-social-metrics/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/sync-social-metrics/route.ts
@@ -5,7 +5,7 @@ import { withWorkspace } from "@/lib/auth";
import { getEffectiveBountyPeriod } from "@/lib/bounty/api/bounty-availability";
import { getBountyOrThrow } from "@/lib/bounty/api/get-bounty-or-throw";
import { getSocialMetricsUpdates } from "@/lib/bounty/api/get-social-metrics-updates";
-import { isBountyExpired, isBountyStarted } from "@/lib/bounty/bounty-period";
+import { isBountyEnded, isBountyStarted } from "@/lib/bounty/bounty-period";
import { resolveBountyDetails } from "@/lib/bounty/utils";
import { qstash } from "@/lib/cron";
import { prisma } from "@/lib/prisma";
@@ -123,7 +123,7 @@ export const POST = withWorkspace(
});
}
- if (isBountyExpired(endsAt)) {
+ if (isBountyEnded(endsAt)) {
throw new DubApiError({
code: "bad_request",
message: "Social metrics can't be synced after the bounty ends.",
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index 596e18c4c7..61a2e79c63 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -10,6 +10,7 @@ import {
bountyEligibilityIncludes,
buildBountyEligibilityWhere,
getEffectiveBountyPeriod,
+ isPartnerEligibleForBounty,
} from "@/lib/bounty/api/bounty-availability";
import { generatePerformanceBountyName } from "@/lib/bounty/api/generate-performance-bounty-name";
import { validateBounty } from "@/lib/bounty/api/validate-bounty";
@@ -110,18 +111,23 @@ export const GET = withWorkspace(
};
// Transform the bounties to the response schema
- const now = new Date();
const data = bounties.flatMap((bounty) => {
if (programEnrollment) {
- const { startsAt, endsAt } = getEffectiveBountyPeriod({
- programEnrollment,
+ const isEligible = isPartnerEligibleForBounty({
+ program: programEnrollment.program,
bounty,
+ programEnrollment,
});
- if (now < startsAt || (endsAt && now > endsAt)) {
+ if (!isEligible) {
return [];
}
+ const { startsAt, endsAt } = getEffectiveBountyPeriod({
+ programEnrollment,
+ bounty,
+ });
+
bounty = {
...bounty,
startsAt,
diff --git a/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts b/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
index 4122f6ae30..fac6aa6efe 100644
--- a/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
+++ b/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
@@ -1,7 +1,7 @@
import { createId } from "@/lib/api/create-id";
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { evaluateWorkflowConditions } from "@/lib/api/workflows/evaluate-workflow-conditions";
-import { canPartnerSubmitBounty } from "@/lib/bounty/api/bounty-availability";
+import { isPartnerEligibleForBounty } from "@/lib/bounty/api/bounty-availability";
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
import { aggregatePartnerLinksStats } from "@/lib/partners/aggregate-partner-links-stats";
@@ -168,15 +168,15 @@ export async function POST(req: Request) {
continue;
}
- const canSubmitBounty = canPartnerSubmitBounty({
+ const isEligible = isPartnerEligibleForBounty({
program: bounty.program,
bounty,
programEnrollment,
});
- if (!canSubmitBounty) {
+ if (!isEligible) {
console.log(
- `Partner ${programEnrollment.partnerId} is not eligible to submit bounty ${bountyId}.`,
+ `Partner ${programEnrollment.partnerId} is not eligible for bounty ${bountyId}.`,
);
continue;
}
diff --git a/apps/web/app/(ee)/api/cron/bounties/sync-social-metrics/route.ts b/apps/web/app/(ee)/api/cron/bounties/sync-social-metrics/route.ts
index a99496993e..8f48189e90 100644
--- a/apps/web/app/(ee)/api/cron/bounties/sync-social-metrics/route.ts
+++ b/apps/web/app/(ee)/api/cron/bounties/sync-social-metrics/route.ts
@@ -1,6 +1,6 @@
import { getEffectiveBountyPeriod } from "@/lib/bounty/api/bounty-availability";
import { getSocialMetricsUpdates } from "@/lib/bounty/api/get-social-metrics-updates";
-import { isBountyExpired } from "@/lib/bounty/bounty-period";
+import { isBountyEnded } from "@/lib/bounty/bounty-period";
import { resolveBountyDetails } from "@/lib/bounty/utils";
import { qstash } from "@/lib/cron";
import { withCron } from "@/lib/cron/with-cron";
@@ -134,7 +134,7 @@ export const POST = withCron(async ({ rawBody }) => {
bounty,
});
- if (isBountyExpired(endsAt)) {
+ if (isBountyEnded(endsAt)) {
continue;
}
diff --git a/apps/web/lib/bounty/api/bounty-availability.ts b/apps/web/lib/bounty/api/bounty-availability.ts
index 0fcc8e9c5c..a09a519b92 100644
--- a/apps/web/lib/bounty/api/bounty-availability.ts
+++ b/apps/web/lib/bounty/api/bounty-availability.ts
@@ -8,7 +8,7 @@ import {
ProgramEnrollment,
} from "@prisma/client";
import { addDays } from "date-fns";
-import { isBountyExpired, isBountyStarted } from "../bounty-period";
+import { isBountyEnded, isBountyStarted } from "../bounty-period";
type PartnerBountyEligibilityInput = {
program: Pick<Program, "defaultGroupId">;
@@ -156,7 +156,7 @@ export function isPartnerEligibleForBounty({
return false;
}
- if (isBountyExpired(endsAt)) {
+ if (isBountyEnded(endsAt)) {
console.log(`Bounty ${bounty.id} is expired.`);
return false;
}
diff --git a/apps/web/lib/bounty/bounty-period.ts b/apps/web/lib/bounty/bounty-period.ts
index ec1eaa3559..c6b859bbc3 100644
--- a/apps/web/lib/bounty/bounty-period.ts
+++ b/apps/web/lib/bounty/bounty-period.ts
@@ -95,7 +95,7 @@ export function isBountyStarted(startsAt: Date) {
return startsAt <= new Date();
}
-export function isBountyExpired(endsAt: Date | null) {
+export function isBountyEnded(endsAt: Date | null) {
return endsAt !== null && endsAt <= new Date();
}