The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor bounty eligibility and query logic
Kiran Kbe398f427fb8
diff --git a/apps/web/lib/api/bounties/get-bounties-by-groups.ts b/apps/web/lib/api/bounties/get-bounties-by-groups.tsindex fdaab5cf52..5cc40193c0 100644--- a/apps/web/lib/api/bounties/get-bounties-by-groups.ts+++ b/apps/web/lib/api/bounties/get-bounties-by-groups.ts@@ -8,15 +8,9 @@ export async function getBountiesByGroups({programId: string;groupIds: string[];}) {- const now = new Date();-const bounties = await prisma.bounty.findMany({where: {programId,- startsAt: {- lte: now,- },- OR: [{ endsAt: null }, { endsAt: { gt: now } }],AND: [{OR: [diff --git a/apps/web/lib/api/bounties/get-bounty-submissions.ts b/apps/web/lib/api/bounties/get-bounty-submissions.tsindex 4396d082c0..9cef73685f 100644--- a/apps/web/lib/api/bounties/get-bounty-submissions.ts+++ b/apps/web/lib/api/bounties/get-bounty-submissions.ts@@ -17,15 +17,7 @@ export async function getBountySubmissions({const submissions = await prisma.bountySubmission.findMany({where: {bountyId,- ...(status- ? {- status,- }- : {- status: {- not: "rejected",- },- }),+ ...(status ? { status } : { status: { not: "rejected" } }),...(groupId && {programEnrollment: {groupId,diff --git a/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.ts b/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.tsindex fa854273e8..38b0930a33 100644--- a/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.ts+++ b/apps/web/lib/api/bounties/trigger-draft-bounty-submissions.ts@@ -1,6 +1,7 @@import { qstash } from "@/lib/cron";import { prisma } from "@dub/prisma";import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";+import { Bounty } from "@prisma/client";import { getBountiesByGroups } from "./get-bounties-by-groups";// TODO:@@ -57,9 +58,8 @@ export async function triggerDraftBountySubmissionCreation({);for (const groupId in bountiesByGroups) {- const eligibleBounties = bountiesByGroups[groupId].filter(- (bounty) =>- bounty.type === "performance" && bounty.currentStatsOnly === false,+ const eligibleBounties = bountiesByGroups[groupId].filter((bounty) =>+ isEligiblePerformanceBounty(bounty),);if (eligibleBounties.length === 0) {@@ -93,3 +93,14 @@ export async function triggerDraftBountySubmissionCreation({);}}++function isEligiblePerformanceBounty(bounty: Bounty) {+ const now = new Date();++ if (bounty.type !== "performance") return false;+ if (bounty.currentStatsOnly) return false;+ if (bounty.startsAt > now) return false;+ if (bounty.endsAt && bounty.endsAt <= now) return false;++ return true;+}