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.

add totalSubmissions to response

Kiran Kb82dc11a07cf
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index 329a6049ba..e8ba6292dd 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -12,15 +12,27 @@ import { z } from "zod";
export const GET = withWorkspace(async ({ workspace }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
- const bounties = await prisma.bounty.findMany({
+ let bounties = await prisma.bounty.findMany({
where: {
programId,
},
orderBy: {
createdAt: "desc",
},
+ include: {
+ _count: {
+ select: {
+ submissions: true,
+ },
+ },
+ },
});
+ bounties = bounties.map((bounty) => ({
+ ...bounty,
+ totalSubmissions: bounty._count.submissions,
+ }));
+
return NextResponse.json(z.array(BountySchema).parse(bounties));
});
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
index ce1f15d41a..cd3e6ca0bf 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/bounty-card.tsx
@@ -5,11 +5,6 @@ import { formatDate } from "@dub/utils";
import { Trophy } from "lucide-react";
export function BountyCard({ bounty }: { bounty: BountyProps }) {
- const { name, startsAt, endsAt } = bounty;
-
- const total = 1000;
- const completed = 400;
-
return (
<ProgramOverviewCard className="cursor-pointer p-5 transition-shadow hover:shadow-lg">
<div className="flex flex-col gap-5">
@@ -21,17 +16,17 @@ export function BountyCard({ bounty }: { bounty: BountyProps }) {
<div className="flex flex-col gap-1.5">
<h3 className="line-clamp-1 text-sm font-semibold text-neutral-900">
- {name}
+ {bounty.name}
</h3>
<div className="flex items-center space-x-2">
<CalendarDays className="size-4" />
<span className="text-sm text-neutral-500">
- {formatDate(startsAt, { month: "short" })}
- {endsAt && (
+ {formatDate(bounty.startsAt, { month: "short" })}
+ {bounty.endsAt && (
<>
{" → "}
- {formatDate(endsAt, { month: "short" })}
+ {formatDate(bounty.endsAt, { month: "short" })}
</>
)}
</span>
@@ -40,8 +35,10 @@ export function BountyCard({ bounty }: { bounty: BountyProps }) {
<div className="flex items-center space-x-2">
<Users className="size-4" />
<div className="text-sm text-neutral-500">
- <span className="font-medium text-neutral-700">{completed}</span>{" "}
- of <span className="font-medium text-neutral-700">{total}</span>{" "}
+ <span className="font-medium text-neutral-700">{100}</span> of{" "}
+ <span className="font-medium text-neutral-700">
+ {bounty.totalSubmissions}
+ </span>{" "}
partners completed
</div>
</div>
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 775266aa75..5a973be4dc 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -37,6 +37,7 @@ export const BountySchema = z.object({
startsAt: z.date(),
endsAt: z.date().nullable(),
rewardAmount: z.number(),
+ totalSubmissions: z.number(),
});
export const BountySubmissionSchema = z.object({
@@ -48,7 +49,6 @@ export const BountySubmissionSchema = z.object({
reviewedAt: z.date().nullable(),
rejectionReason: z.string().nullable(),
rejectionNote: z.string().nullable(),
-
partner: PartnerSchema.pick({
id: true,
name: true,
@@ -61,11 +61,11 @@ export const BountySubmissionSchema = z.object({
amount: true,
earnings: true,
status: true,
- }),
+ }).nullable(),
user: UserSchema.pick({
id: true,
name: true,
email: true,
image: true,
- }),
+ }).nullable(),
});