The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
dynamically run sync-social-metrics
Steven Teydac0eaa2a483
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.tsindex 7931c33a38..122f7207f2 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@@ -67,6 +67,13 @@ export const POST = withWorkspace(: undefined,});+ if (isBountyEnded(bounty.endsAt)) {+ throw new DubApiError({+ code: "bad_request",+ message: "Social metrics can't be synced after the bounty ends.",+ });+ }+const bountyInfo = resolveBountyDetails(bounty);if (!bountyInfo?.socialMetrics) {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.tsindex 5c738e8c01..b071005a31 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,4 +1,7 @@-import { getEffectiveBountyPeriod } from "@/lib/bounty/api/bounty-availability";+import {+ bountyEligibilityIncludes,+ isPartnerEligibleForBounty,+} from "@/lib/bounty/api/bounty-availability";import { getSocialMetricsUpdates } from "@/lib/bounty/api/get-social-metrics-updates";import { isBountyEnded } from "@/lib/bounty/bounty-period";import { hasReachedSocialMetricsEarningCap } from "@/lib/bounty/social-metrics-milestones";@@ -34,11 +37,13 @@ export const POST = withCron(async ({ rawBody }) => {id: bountyId,},include: {+ ...bountyEligibilityIncludes,program: {select: {name: true,slug: true,supportEmail: true,+ defaultGroupId: true,},},},@@ -48,6 +53,10 @@ export const POST = withCron(async ({ rawBody }) => {return logAndRespond(`Bounty ${bountyId} not found. Skipping...`);}+ if (isBountyEnded(bounty.endsAt)) {+ return logAndRespond(`Bounty ${bountyId} has ended. Skipping...`);+ }+const bountyInfo = resolveBountyDetails(bounty);if (!bountyInfo?.hasSocialMetrics) {@@ -88,6 +97,13 @@ export const POST = withCron(async ({ rawBody }) => {programEnrollment: {select: {createdAt: true,+ groupId: true,+ status: true,+ programPartnerTags: {+ select: {+ partnerTagId: true,+ },+ },},},},@@ -118,12 +134,11 @@ export const POST = withCron(async ({ rawBody }) => {return false;}- const { endsAt } = getEffectiveBountyPeriod({- programEnrollment: submission.programEnrollment,+ return isPartnerEligibleForBounty({+ program: bounty.program,bounty,+ programEnrollment: submission.programEnrollment,});-- return !isBountyEnded(endsAt);});let syncedCount = 0;