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.

Handle nullable startsAt for relative bounties and skip partner notify cron.

Kiran K441a1c0d43f0
diff --git a/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts b/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts
index 8b93144b28..8f1bd4c298 100644
--- a/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts
+++ b/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts
@@ -7,7 +7,7 @@ import { ACTIVE_ENROLLMENT_STATUSES } from "@/lib/zod/schemas/partners";
import { sendBatchEmail } from "@dub/email";
import NewBountyAvailable from "@dub/email/templates/new-bounty-available";
import { APP_DOMAIN_WITH_NGROK, log } from "@dub/utils";
-import { NotificationEmailType } from "@prisma/client";
+import { BountyStartMode, NotificationEmailType } from "@prisma/client";
import { differenceInMinutes } from "date-fns";
import * as z from "zod/v4";
import { logAndRespond } from "../../utils";
@@ -69,28 +69,36 @@ export async function POST(req: Request) {
});
}
- const diffMinutes = differenceInMinutes(bounty.startsAt, new Date());
-
- if (diffMinutes >= 10) {
+ if (bounty.startMode === BountyStartMode.relative) {
return logAndRespond(
- `Bounty ${bountyId} not started yet, it will start at ${bounty.startsAt.toISOString()}`,
+ `Bounty ${bountyId} is relative-start; partner notifications skipped.`,
);
}
- // Find groupIds
- const groupIds = bounty.groups.map(({ groupId }) => groupId);
+ if (bounty.startsAt) {
+ const diffMinutes = differenceInMinutes(bounty.startsAt, new Date());
+
+ if (diffMinutes >= 10) {
+ return logAndRespond(
+ `Bounty ${bountyId} not started yet, it will start at ${bounty.startsAt.toISOString()}`,
+ );
+ }
+ }
+
+ const bountyGroupIds = bounty.groups.map(({ groupId }) => groupId);
+
console.log(
`Bounty ${bountyId} is applicable to ${
- groupIds.length === 0 ? "all" : groupIds.length
- } groups (groupIds: ${JSON.stringify(groupIds)})`,
+ bountyGroupIds.length === 0 ? "all" : bountyGroupIds.length
+ } groups (groupIds: ${JSON.stringify(bountyGroupIds)})`,
);
const programEnrollments = await prisma.programEnrollment.findMany({
where: {
programId: bounty.programId,
- ...(groupIds.length > 0 && {
+ ...(bountyGroupIds.length > 0 && {
groupId: {
- in: groupIds,
+ in: bountyGroupIds,
},
}),
status: {
diff --git a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
index f52e49ec86..49b73ed0ef 100644
--- a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
+++ b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
@@ -121,6 +121,7 @@ export const executeCompleteBountyWorkflow = async ({
if (
bounty.performanceScope === "new" &&
customerFirstSaleAt &&
+ bounty.startsAt &&
customerFirstSaleAt < bounty.startsAt
) {
console.log(
diff --git a/apps/web/lib/bounty/api/get-group-bounty-summaries.ts b/apps/web/lib/bounty/api/get-group-bounty-summaries.ts
index 8acc655367..4e29bdb625 100644
--- a/apps/web/lib/bounty/api/get-group-bounty-summaries.ts
+++ b/apps/web/lib/bounty/api/get-group-bounty-summaries.ts
@@ -5,7 +5,7 @@ type BountyEligibilityCandidate = {
id: string;
name: string | null;
type: BountyType;
- startsAt: Date;
+ startsAt: Date | null;
endsAt: Date | null;
archivedAt: Date | null;
groups: { groupId: string }[];
@@ -26,7 +26,7 @@ export function filterActiveGroupBounties(
return false;
}
- if (bounty.startsAt > now) {
+ if (bounty.startsAt && bounty.startsAt > now) {
return false;
}
diff --git a/apps/web/lib/bounty/api/trigger-draft-bounty-submissions.ts b/apps/web/lib/bounty/api/trigger-draft-bounty-submissions.ts
index 068653dd8e..e37d8ee277 100644
--- a/apps/web/lib/bounty/api/trigger-draft-bounty-submissions.ts
+++ b/apps/web/lib/bounty/api/trigger-draft-bounty-submissions.ts
@@ -97,7 +97,7 @@ function isEligiblePerformanceBounty(bounty: Bounty) {
if (bounty.type !== "performance") return false;
if (bounty.performanceScope === "new") return false;
- if (bounty.startsAt > now) return false;
+ if (bounty.startsAt && bounty.startsAt > now) return false;
if (bounty.endsAt && bounty.endsAt <= now) return false;
return true;
diff --git a/apps/web/lib/integrations/slack/transform.ts b/apps/web/lib/integrations/slack/transform.ts
index c6dc3fa23a..f3288b5255 100644
--- a/apps/web/lib/integrations/slack/transform.ts
+++ b/apps/web/lib/integrations/slack/transform.ts
@@ -1,4 +1,5 @@
import { isFirstConversion } from "@/lib/analytics/is-first-conversion";
+import { getProgramBountyMeta } from "@/lib/bounty/bounty-period";
import { getBountyRewardDescription } from "@/lib/bounty/rewards";
import { APP_DOMAIN, COUNTRIES, currencyFormatter, truncate } from "@dub/utils";
import { LinkWebhookEvent } from "dub/models/components";
@@ -451,6 +452,8 @@ const bountyTemplates = ({
type,
startsAt,
endsAt,
+ startMode,
+ endsAfterDays,
} = data;
const eventMessages = {
@@ -464,6 +467,13 @@ const bountyTemplates = ({
submissionRequirements,
});
+ const { dateRangeLabel } = getProgramBountyMeta({
+ startsAt,
+ endsAt,
+ startMode,
+ endsAfterDays,
+ });
+
const hrefToBounty = `${APP_DOMAIN}/program/bounties/${id}`;
return {
@@ -497,7 +507,7 @@ const bountyTemplates = ({
},
{
type: "mrkdwn",
- text: `*Duration*\n${new Date(startsAt).toLocaleDateString()}${endsAt ? ` - ${new Date(endsAt).toLocaleDateString()}` : " (No end date)"}`,
+ text: `*Duration*\n${dateRangeLabel}`,
},
],
},