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.

Update bounty groups

Tim Wilson15f552f86e8b
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
index fdb69ed161..0fa1329c30 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
@@ -39,6 +39,17 @@ export const PATCH = withWorkspace(async ({ workspace, params, req }) => {
programId,
});
+ const groups = groupIds?.length
+ ? await prisma.partnerGroup.findMany({
+ where: {
+ programId,
+ id: {
+ in: groupIds,
+ },
+ },
+ })
+ : [];
+
await prisma.bounty.update({
where: {
id: bounty.id,
@@ -48,6 +59,13 @@ export const PATCH = withWorkspace(async ({ workspace, params, req }) => {
submissionRequirements: data.submissionRequirements ?? Prisma.JsonNull,
startsAt: new Date(data.startsAt!),
endsAt: data.endsAt ? new Date(data.endsAt) : null,
+
+ groups: {
+ deleteMany: {},
+ create: groups?.map((group) => ({
+ groupId: group.id,
+ })),
+ },
},
});
diff --git a/apps/web/app/(ee)/api/bounties/route.ts b/apps/web/app/(ee)/api/bounties/route.ts
index e1af716ab8..c35632c2fc 100644
--- a/apps/web/app/(ee)/api/bounties/route.ts
+++ b/apps/web/app/(ee)/api/bounties/route.ts
@@ -41,6 +41,7 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
startsAt,
endsAt,
submissionRequirements,
+ groupIds,
} = createBountySchema.parse(await parseRequestBody(req));
const workflow = await createWorkflow({
@@ -49,11 +50,24 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
},
workflow: {
trigger: "clicks",
- triggerConditions: {},
- actions: {},
+ triggerConditions: {
+ conditions: [],
+ },
+ actions: [],
},
});
+ const groups = groupIds?.length
+ ? await prisma.partnerGroup.findMany({
+ where: {
+ programId,
+ id: {
+ in: groupIds,
+ },
+ },
+ })
+ : null;
+
const bounty = await prisma.bounty.create({
data: {
id: createId({ prefix: "bounty_" }),
@@ -66,6 +80,16 @@ export const POST = withWorkspace(async ({ workspace, req }) => {
endsAt,
rewardAmount,
submissionRequirements: submissionRequirements ?? Prisma.JsonNull,
+
+ ...(groups?.length && {
+ groups: {
+ createMany: {
+ data: groups?.map((group) => ({
+ groupId: group.id,
+ })),
+ },
+ },
+ }),
},
});
diff --git a/apps/web/lib/api/create-id.ts b/apps/web/lib/api/create-id.ts
index 89eef87ffb..f924f4d172 100644
--- a/apps/web/lib/api/create-id.ts
+++ b/apps/web/lib/api/create-id.ts
@@ -29,8 +29,8 @@ const prefixes = [
"audit_",
"import_",
"grp_",
- "bounty_", // TODO: Finalize this
- "bounty_submission_", // TODO: Finalize this
+ "bounty_", // TODO: [bounties] Finalize this
+ "bounty_submission_", // TODO: [bounties] Finalize this
"wf_",
] as const;