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.

Move embed bounty submissions under bountyId and tighten eligibility checks.

Kiran K1ccf5a2aec14
diff --git a/apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/social-content-stats/route.ts b/apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/social-content-stats/route.ts
index 0a1e80f6a4..7496e7ccc4 100644
--- a/apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/social-content-stats/route.ts
+++ b/apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/social-content-stats/route.ts
@@ -1,5 +1,6 @@
import { DubApiError } from "@/lib/api/errors";
import { getSocialContent } from "@/lib/api/scrape-creators/get-social-content";
+import { canPartnerSubmitBounty } from "@/lib/bounty/api/bounty-availability";
import { getBountyOrThrow } from "@/lib/bounty/api/get-bounty-or-throw";
import { resolveBountyDetails } from "@/lib/bounty/utils";
import { withReferralsEmbedToken } from "@/lib/embed/referrals/auth";
@@ -13,7 +14,7 @@ const searchParamsSchema = z.object({
// GET /api/embed/referrals/bounties/[bountyId]/social-content-stats
export const GET = withReferralsEmbedToken(
- async ({ programEnrollment, searchParams, params }) => {
+ async ({ program, programEnrollment, searchParams, params }) => {
const { bountyId } = params;
const { url } = searchParamsSchema.parse(searchParams);
@@ -32,52 +33,33 @@ export const GET = withReferralsEmbedToken(
bountyId,
programId: programEnrollment.programId,
include: {
- groups: true,
+ groups: {
+ select: {
+ groupId: true,
+ },
+ },
},
});
- if (bounty.groups.length > 0) {
- const isInGroup = bounty.groups.some(
- ({ groupId }) => groupId === programEnrollment.groupId,
- );
-
- if (!isInGroup) {
- throw new DubApiError({
- code: "forbidden",
- message: "You are not allowed to access this bounty.",
- });
- }
- }
-
- const now = new Date();
-
- if (bounty.startsAt && bounty.startsAt > now) {
- throw new DubApiError({
- code: "bad_request",
- message: "This bounty is not yet available.",
- });
- }
-
- if (bounty.endsAt && bounty.endsAt < now) {
- throw new DubApiError({
- code: "bad_request",
- message: "This bounty is no longer available.",
- });
- }
+ const bountyInfo = resolveBountyDetails(bounty);
- if (bounty.archivedAt) {
+ if (!bountyInfo?.socialMetrics) {
throw new DubApiError({
code: "bad_request",
- message: "This bounty is archived.",
+ message: "This bounty does not have social content requirements.",
});
}
- const bountyInfo = resolveBountyDetails(bounty);
+ const canSubmitBounty = canPartnerSubmitBounty({
+ program,
+ bounty,
+ programEnrollment,
+ });
- if (!bountyInfo?.socialMetrics) {
+ if (!canSubmitBounty) {
throw new DubApiError({
- code: "bad_request",
- message: "This bounty does not have social content requirements.",
+ code: "not_found",
+ message: "Bounty not found.",
});
}
diff --git a/apps/web/app/(ee)/api/embed/referrals/submissions/route.ts b/apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/submissions/route.ts
similarity index 80%
rename from apps/web/app/(ee)/api/embed/referrals/submissions/route.ts
rename to apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/submissions/route.ts
index b2edc07363..5504f3704b 100644
--- a/apps/web/app/(ee)/api/embed/referrals/submissions/route.ts
+++ b/apps/web/app/(ee)/api/embed/referrals/bounties/[bountyId]/submissions/route.ts
@@ -5,11 +5,12 @@ import { prisma } from "@/lib/prisma";
import { createBountySubmissionInputSchema } from "@/lib/zod/schemas/bounties";
import { NextResponse } from "next/server";
-// POST /api/embed/referrals/submissions – submit a bounty via embed token
+// POST /api/embed/referrals/bounties/[bountyId]/submissions – submit a bounty via embed token
export const POST = withReferralsEmbedToken(
- async ({ req, programEnrollment }) => {
+ async ({ req, programEnrollment, params }) => {
+ const { bountyId } = params;
const parsedInput = createBountySubmissionInputSchema
- .omit({ programId: true })
+ .omit({ programId: true, bountyId: true })
.parse(await parseRequestBody(req));
const partner = await prisma.partner.findUniqueOrThrow({
@@ -26,6 +27,7 @@ export const POST = withReferralsEmbedToken(
const submissionHandler = new BountySubmissionHandler({
...parsedInput,
+ bountyId,
programId: programEnrollment.programId,
partner,
});
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-fields.tsx b/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-fields.tsx
index 0e60298ccf..4c115764bf 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-fields.tsx
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-fields.tsx
@@ -325,25 +325,21 @@ export function EmbedSocialUrlField({
/>
<span>Posted from your account</span>
</li>
- {bounty.startsAt && (
- <li
+ <li
+ className={cn(
+ "flex items-center gap-1 text-xs font-medium transition-colors",
+ isAfterStartDate ? "text-content-success" : "text-content-muted",
+ )}
+ >
+ <CircleCheck
+ variant="fill"
className={cn(
- "flex items-center gap-1 text-xs font-medium transition-colors",
+ "size-2.5 transition-opacity",
isAfterStartDate ? "text-content-success" : "text-content-muted",
)}
- >
- <CircleCheck
- variant="fill"
- className={cn(
- "size-2.5 transition-opacity",
- isAfterStartDate
- ? "text-content-success"
- : "text-content-muted",
- )}
- />
- <span>{`Posted after ${formatDate(bounty.startsAt, { month: "short", day: "numeric", year: "numeric" })}`}</span>
- </li>
- )}
+ />
+ <span>{`Posted after ${formatDate(bounty.startsAt, { month: "short", day: "numeric", year: "numeric" })}`}</span>
+ </li>
</ul>
</div>
);
diff --git a/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-form.tsx b/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-form.tsx
index 2b19e1c698..d3159fe67e 100644
--- a/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-form.tsx
+++ b/apps/web/app/(ee)/app.dub.co/embed/referrals/bounties/submission-form.tsx
@@ -171,21 +171,23 @@ export function EmbedBountySubmissionForm({
isDraft ? setIsDraftSaving(true) : setIsSubmitting(true);
try {
- const res = await fetch("/api/embed/referrals/submissions", {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- Authorization: `Bearer ${token}`,
+ const res = await fetch(
+ `/api/embed/referrals/bounties/${bounty.id}/submissions`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Authorization: `Bearer ${token}`,
+ },
+ body: JSON.stringify({
+ files: completedFiles,
+ urls: submissionUrls,
+ description: description || undefined,
+ isDraft,
+ periodNumber,
+ }),
},
- body: JSON.stringify({
- bountyId: bounty.id,
- files: completedFiles,
- urls: submissionUrls,
- description: description || undefined,
- isDraft,
- periodNumber,
- }),
- });
+ );
if (!res.ok) {
const err = await res.json().catch(() => ({}));