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.

return the groups

Kiran K1ce2287a1a1f
diff --git a/apps/web/lib/api/bounties/get-bounties.ts b/apps/web/lib/api/bounties/get-bounties.ts
index 030255953a..aa1b166e8c 100644
--- a/apps/web/lib/api/bounties/get-bounties.ts
+++ b/apps/web/lib/api/bounties/get-bounties.ts
@@ -34,10 +34,24 @@ export async function getBounties(filters: BountyFilters) {
${
includeExpandedFields
? Prisma.sql`
- COUNT(DISTINCT pe.partnerId) as partnersCount
+ COUNT(DISTINCT pe.partnerId) as partnersCount,
+ COALESCE(
+ (
+ SELECT JSON_ARRAYAGG(
+ JSON_OBJECT('id', bgSub.groupId)
+ )
+ FROM (
+ SELECT bgSub.groupId
+ FROM BountyGroup bgSub
+ WHERE bgSub.bountyId = b.id
+ ) bgSub
+ ),
+ JSON_ARRAY()
+ ) as groups
`
: Prisma.sql`
- 0 as partnersCount
+ 0 as partnersCount,
+ JSON_ARRAY() as groups
`
}
FROM Bounty b
@@ -50,7 +64,7 @@ export async function getBounties(filters: BountyFilters) {
: Prisma.sql``
}
WHERE b.programId = ${programId}
- GROUP BY b.id
+ GROUP BY b.id, b.name, b.description, b.type, b.startsAt, b.endsAt, b.rewardAmount, b.submissionRequirements
ORDER BY ${Prisma.raw(sortColumnsMap[sortBy])} ${Prisma.raw(sortOrder)}
LIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}
`) satisfies Array<any>;
@@ -58,5 +72,6 @@ export async function getBounties(filters: BountyFilters) {
return bounties.map((bounty) => ({
...bounty,
partnersCount: Number(bounty.partnersCount),
+ groups: bounty.groups.filter((group) => group !== null),
}));
}
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index 5274dddb22..eda4549c1f 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -5,6 +5,7 @@ import {
} from "@dub/prisma/client";
import { z } from "zod";
import { CommissionSchema } from "./commissions";
+import { GroupSchema } from "./groups";
import { booleanQuerySchema, getPaginationQuerySchema } from "./misc";
import { EnrolledPartnerSchema } from "./partners";
import { UserSchema } from "./users";
@@ -55,6 +56,13 @@ export const BountySchema = z.object({
export const BountySchemaExtended = BountySchema.extend({
partnersCount: z.number().default(0),
+ groups: z
+ .array(
+ GroupSchema.pick({
+ id: true,
+ }),
+ )
+ .nullable(),
});
export const BountySubmissionFileSchema = z.object({