Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
290 commits
Select commit Hold shift + click to select a range
29e6c1a
Merge branch 'main' into bounties
steven-tey Aug 15, 2025
f348ce7
WIP group mult-select
TWilson023 Aug 15, 2025
6a897d4
Merge branch 'main' into bounties
steven-tey Aug 15, 2025
721b403
Update groups-multi-select.tsx
TWilson023 Aug 15, 2025
7cfc109
Merge branch 'bounties' of github.com:dubinc/dub into bounties
TWilson023 Aug 15, 2025
67d9c5c
Add conditional logic section
TWilson023 Aug 15, 2025
0b42d8b
Merge branch 'main' into bounties
devkiran Aug 17, 2025
eb3fc04
Merge branch 'main' into bounties
devkiran Aug 18, 2025
8a7535a
Bounty endpoint updates
TWilson023 Aug 18, 2025
aa4fb50
partners -> partnersCount
TWilson023 Aug 18, 2025
3630f73
WIP+fixes
TWilson023 Aug 18, 2025
11e6bd0
WIP bounty logic
TWilson023 Aug 18, 2025
2d7ff5d
Add (temporary?) performance logic stuff
TWilson023 Aug 19, 2025
0d331b6
Add bounty card menu
TWilson023 Aug 19, 2025
934cf3a
WIP edit bounties
TWilson023 Aug 19, 2025
c43e773
Edit bounties
TWilson023 Aug 19, 2025
9a90d58
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 19, 2025
cee46c1
workflow wip
devkiran Aug 19, 2025
421b62d
Update workflows.ts
devkiran Aug 19, 2025
c6c4ec9
Update workflows.ts
devkiran Aug 19, 2025
dc9720b
Update workflows.ts
devkiran Aug 19, 2025
52902f1
Merge branch 'main' into bounties
steven-tey Aug 19, 2025
ddd434e
Delete bounties
TWilson023 Aug 19, 2025
5d89265
Merge branch 'bounties' of github.com:dubinc/dub into bounties
TWilson023 Aug 19, 2025
15f552f
Update bounty groups
TWilson023 Aug 19, 2025
079c5ab
Update workflows.ts
devkiran Aug 20, 2025
ea70224
Update workflow.prisma
devkiran Aug 20, 2025
e36a5f1
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 20, 2025
5f9abaa
workflow schema
devkiran Aug 20, 2025
f9236e7
Update workflows.ts
devkiran Aug 20, 2025
0b35358
add workflow type
devkiran Aug 20, 2025
2105b55
Update add-edit-bounty-sheet.tsx
devkiran Aug 20, 2025
44436b0
Update bounty-list.tsx
devkiran Aug 20, 2025
3da1d3b
create workflow for performance based bounty
devkiran Aug 20, 2025
29c32cd
wip validatePerformanceBounty
devkiran Aug 20, 2025
51cadc0
Implement performance bounty validation and commission creation logic…
devkiran Aug 20, 2025
e78f8dc
Refactor bounty workflow handling: remove validatePerformanceBounty f…
devkiran Aug 20, 2025
a16eed1
Update create-partner-commission.ts
devkiran Aug 20, 2025
7f28083
Update workflow.prisma
devkiran Aug 20, 2025
8f74424
Update execute-bounty-workflow.ts
devkiran Aug 20, 2025
5803a71
reject a bounty submission
devkiran Aug 20, 2025
6166191
Approve a bounty submission
devkiran Aug 20, 2025
d0ad3d2
Update route.ts
devkiran Aug 20, 2025
a074e3a
update /api/bounties/stats
devkiran Aug 20, 2025
d1f6e57
Update bounty-card.tsx
devkiran Aug 20, 2025
a4d2458
Update bounty.ts
devkiran Aug 20, 2025
4b338c8
Hide submission requirements for performance based bounty
devkiran Aug 20, 2025
5bec3af
Refactor BountyInfo to use useBountyStats for submission
devkiran Aug 20, 2025
0089fb1
Fix the submissions table
devkiran Aug 20, 2025
a086659
Fix bounties empty state create button
TWilson023 Aug 20, 2025
3fd735a
Merge branch 'bounties' of github.com:dubinc/dub into bounties
TWilson023 Aug 20, 2025
17aca94
Update groups-multi-select.tsx
TWilson023 Aug 20, 2025
e80fa25
WIP `partners.` bounties
TWilson023 Aug 20, 2025
07258f0
Update bounty-card.tsx
TWilson023 Aug 20, 2025
67a277d
Bounty card tweaks
TWilson023 Aug 20, 2025
7ed2bf8
approve and reject bounty submissions
devkiran Aug 20, 2025
15ea7ee
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 20, 2025
247c8d1
Add back button from bounty details page to the list page
devkiran Aug 20, 2025
6232deb
Update bounty.prisma
devkiran Aug 20, 2025
bc8a3f2
add BountyHeaderTitle
devkiran Aug 20, 2025
80e4bdf
Update bounties.ts
devkiran Aug 20, 2025
36481d0
Update bounty.prisma
devkiran Aug 20, 2025
4257e7d
wip email templates
devkiran Aug 20, 2025
a533831
Merge branch 'main' into bounties
devkiran Aug 20, 2025
aca330a
Add submission statuses
TWilson023 Aug 20, 2025
3332eda
Merge branch 'bounties' of github.com:dubinc/dub into bounties
TWilson023 Aug 20, 2025
5284778
WIP claim bounty modal
TWilson023 Aug 20, 2025
e44a47e
File uploads
TWilson023 Aug 20, 2025
a09496f
Update route.ts
devkiran Aug 21, 2025
ccf6c19
Update bounties.ts
devkiran Aug 21, 2025
f2a9e7d
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 21, 2025
1539fb8
update the submission upload URL
devkiran Aug 21, 2025
12d56d6
improve the workflows
devkiran Aug 21, 2025
47c1105
Merge branch 'main' into bounties
devkiran Aug 21, 2025
a5c087b
fix workflow
devkiran Aug 21, 2025
a958f99
update the id prefixes
devkiran Aug 21, 2025
cf00962
update bounty details sheet
devkiran Aug 21, 2025
de7a161
Refactor bounty thumbnail and add completed email template
devkiran Aug 21, 2025
a65f119
Update bounty-completed.tsx
devkiran Aug 21, 2025
dd4c2b0
Update bounty-rejected.tsx
devkiran Aug 21, 2025
825ba03
Update bounty-approved.tsx
devkiran Aug 21, 2025
e288ebb
Update execute-award-bounty-action.ts
devkiran Aug 21, 2025
6bee6bb
bounty approved email
devkiran Aug 21, 2025
c6f9842
bounty rejected email
devkiran Aug 21, 2025
40ea966
Bounty completed email
devkiran Aug 21, 2025
516a672
Update claim-bounty-modal.tsx
TWilson023 Aug 21, 2025
8ab230a
Update claim-bounty-modal.tsx
TWilson023 Aug 21, 2025
bb5f0d2
Add bounty submission
TWilson023 Aug 21, 2025
1ce2287
return the groups
devkiran Aug 21, 2025
2744d9b
Update get-bounties.ts
devkiran Aug 21, 2025
199021d
Bounty submission success
TWilson023 Aug 21, 2025
8270f39
Trigger workflows on lead and sale events in Stripe webhooks
devkiran Aug 21, 2025
c52110f
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 21, 2025
d883c9d
Bounty submission tweaks + statuses
TWilson023 Aug 21, 2025
8e4677f
Merge branch 'bounties' of github.com:dubinc/dub into bounties
TWilson023 Aug 21, 2025
e8d1a3e
Update add-edit-bounty-sheet.tsx
TWilson023 Aug 21, 2025
67291ec
Misc. fixes
TWilson023 Aug 21, 2025
cb4a4f1
Bounty info updates
TWilson023 Aug 21, 2025
d3a96eb
Bounty submission sheet updates
TWilson023 Aug 21, 2025
d455c14
Update route.ts
TWilson023 Aug 21, 2025
ce1b9b7
Add pending bounty submissions count to sidebar
TWilson023 Aug 21, 2025
b812023
Merge branch 'main' into bounties
steven-tey Aug 21, 2025
3fe3901
Merge branch 'main' into bounties
steven-tey Aug 22, 2025
ca1eec2
Update bounty.prisma
devkiran Aug 22, 2025
f329156
Update create-bounty-submission.ts
devkiran Aug 22, 2025
a1c072b
rename
devkiran Aug 22, 2025
1dff28a
performance based bounty updates
devkiran Aug 22, 2025
72238ae
Update bounty-submission-details-sheet.tsx
devkiran Aug 22, 2025
bda0761
Update bounty-submission-details-sheet.tsx
devkiran Aug 22, 2025
cf767d6
update bounty
devkiran Aug 22, 2025
b2e7782
Create bounty-pending-review.tsx
devkiran Aug 22, 2025
5d59fec
Update create-bounty-submission.ts
devkiran Aug 22, 2025
9ee42ad
Update bounty-pending-review.tsx
devkiran Aug 22, 2025
ebbaae7
send BountyPendingReview email
devkiran Aug 22, 2025
427d538
send BountySubmitted email
devkiran Aug 22, 2025
6895c9d
adjust the schema
devkiran Aug 22, 2025
4620c45
Update bounty-submission-details-sheet.tsx
devkiran Aug 22, 2025
69fed8f
Add partner bounty submission query with filters
devkiran Aug 22, 2025
7c66e61
format
devkiran Aug 22, 2025
15b6333
add bounty webhooks
devkiran Aug 22, 2025
3a12d65
fix sorting
devkiran Aug 22, 2025
91ca50c
fix the sorting again
devkiran Aug 22, 2025
b226892
Add progress circles to submissions table
TWilson023 Aug 22, 2025
2a65705
Update progress-circle.tsx
TWilson023 Aug 22, 2025
256f066
Add performance bounty progress UI
TWilson023 Aug 22, 2025
0268e04
Refactor useBounty hook loading state
devkiran Aug 23, 2025
c99d04a
add additional validation to createBountySubmissionAction
devkiran Aug 23, 2025
d78ac63
add NewBountyPublished email template
devkiran Aug 23, 2025
407fb58
Add cron route for sending bounty published emails
devkiran Aug 23, 2025
20b6f8c
Refactor bounty retrieval and metrics aggregation
devkiran Aug 23, 2025
4a564b3
Enhance bounty submission functionality by defining maximum limits fo…
devkiran Aug 23, 2025
58945bc
Update bounty-completed.tsx
devkiran Aug 23, 2025
2bde778
Update upload-bounty-submission-file.ts
devkiran Aug 23, 2025
b68354f
Add 'newBountySubmitted' notification preference
devkiran Aug 23, 2025
6175ade
Update route.ts
devkiran Aug 23, 2025
73a54c1
Update get-partners-with-bounty-submission.ts
devkiran Aug 23, 2025
1716704
Update types.ts
devkiran Aug 23, 2025
a85849e
Update bounty-submissions-table.tsx
devkiran Aug 23, 2025
aa65e62
Update commission.prisma
devkiran Aug 23, 2025
a71ea11
Merge branch 'main' into bounties
devkiran Aug 23, 2025
e502c3d
Update get-bounties.ts
devkiran Aug 23, 2025
801746c
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 23, 2025
1319991
Refactor bounty stats API and usage
devkiran Aug 24, 2025
2f7bf76
Refactor bounty submissions and partners data structure
devkiran Aug 24, 2025
a3c96d9
Update route.ts
devkiran Aug 24, 2025
a806df5
Update bounty-info.tsx
devkiran Aug 24, 2025
f53e020
Update get-bounties.ts
devkiran Aug 24, 2025
74db347
Update get-bounty-or-throw.ts
devkiran Aug 24, 2025
04ebc1e
Update bounty-info.tsx
devkiran Aug 24, 2025
787c805
Update bounty-card.tsx
devkiran Aug 24, 2025
14c6e6b
Refactor bounty action menu into reusable component
devkiran Aug 24, 2025
df59185
Refactor bounty sheet integration and button logic
devkiran Aug 24, 2025
cc6740c
Add advanced filters to bounty submissions API
devkiran Aug 24, 2025
a034ba3
Merge branch 'main' into bounties
devkiran Aug 25, 2025
ea98ff0
Update execute-award-bounty-action.ts
devkiran Aug 25, 2025
4d360e7
Preserve line breaks in bounty description
devkiran Aug 25, 2025
4897f31
use the prefix for bounty submission
devkiran Aug 25, 2025
6de13ca
Enforce max limits on bounty submission files and URLs
devkiran Aug 25, 2025
803d518
Preserve line breaks in bounty submission description
devkiran Aug 25, 2025
00bdafa
Update execute-award-bounty-action.ts
devkiran Aug 25, 2025
aa23934
Add all completed state to program bounty card
TWilson023 Aug 25, 2025
7d53f87
Workflow context `totalCommissions` -> `totalCommission`
TWilson023 Aug 25, 2025
6e82fda
Bounty completed state updates
TWilson023 Aug 25, 2025
15314c3
Merge branch 'bounties' of https://github.com/dubinc/dub into bounties
devkiran Aug 25, 2025
673583b
format
devkiran Aug 25, 2025
2015e68
Refactor bounty attribute labels and name generation
devkiran Aug 25, 2025
0a089ea
Update transform.ts
devkiran Aug 25, 2025
fac0fdb
Update use-bounty-submissions-count.ts
devkiran Aug 25, 2025
d980ac5
Update bounty-created.json
devkiran Aug 25, 2025
80fd706
Update bounty-updated.json
devkiran Aug 25, 2025
56524aa
Delete bounty.ts
devkiran Aug 25, 2025
3e2033d
Update reject-bounty-submission-modal.tsx
devkiran Aug 25, 2025
e6e4a34
Update bounty-submitted.tsx
devkiran Aug 25, 2025
2ddcdda
Bounty validation/form improvements
TWilson023 Aug 25, 2025
fb4bfb5
Add submission filters
TWilson023 Aug 25, 2025
9ff0c66
Update bounty-thumbnail.tsx
TWilson023 Aug 25, 2025
22c8325
Update bounty-card.tsx
TWilson023 Aug 25, 2025
7f41900
Update bounty-card.tsx
TWilson023 Aug 25, 2025
f8a3298
Fix circular dependency
TWilson023 Aug 25, 2025
49341d6
Badges + filters cleanup
TWilson023 Aug 25, 2025
ecf014b
Add disabledAt field to Workflow model
devkiran Aug 26, 2025
d105fc4
Update route.ts
devkiran Aug 26, 2025
0ed626e
Merge branch 'main' into bounties
devkiran Aug 26, 2025
83bee30
Merge branch 'main' into bounties
devkiran Aug 26, 2025
4d0797e
Update commission.prisma
devkiran Aug 26, 2025
6e92b3e
Update use-bounty-submission-filters.tsx
TWilson023 Aug 26, 2025
64d399e
Update bounty-list.tsx
TWilson023 Aug 26, 2025
b39b32f
Update animated-empty-state.tsx
TWilson023 Aug 26, 2025
402c042
Groups selector fixes
TWilson023 Aug 26, 2025
3f3ab45
Fix performanceCondition in bounty form
TWilson023 Aug 26, 2025
10d8ee1
Performance bounty submission filters
TWilson023 Aug 26, 2025
8e048aa
Update bounty-submission-details-sheet.tsx
TWilson023 Aug 26, 2025
2c73c2b
Update execute-award-bounty-action.ts
TWilson023 Aug 26, 2025
cb0bf06
Merge branch 'main' into bounties
TWilson023 Aug 27, 2025
14a16d3
Merge branch 'main' into bounties
steven-tey Aug 27, 2025
8b332d8
Merge branch 'main' into bounties
steven-tey Aug 27, 2025
41f0bc7
Merge branch 'main' into bounties
steven-tey Aug 27, 2025
963b316
move Resources under Engagement
steven-tey Aug 27, 2025
e9115ca
update NewBountyAvailable email
steven-tey Aug 27, 2025
cc96375
add trailingZeroDisplay: "stripIfInteger"
steven-tey Aug 27, 2025
1312c56
updates to email language
steven-tey Aug 28, 2025
45a2b63
reuse aggregatePartnerLinksStats
steven-tey Aug 28, 2025
4c2171f
fix type error
steven-tey Aug 28, 2025
df69d17
fix date schema
steven-tey Aug 28, 2025
51b8d74
add programBountiesCount
steven-tey Aug 28, 2025
d55d940
disable deletion for bounties with submissions
steven-tey Aug 28, 2025
00ae028
Update menu-item.tsx
steven-tey Aug 28, 2025
7f89f97
remove date rang picker for bounty submissions table
steven-tey Aug 28, 2025
a42f96c
Update create-partner-commission.ts
devkiran Aug 28, 2025
ff8e5be
Merge branch 'main' into bounties
steven-tey Aug 28, 2025
d006698
Merge branch 'main' into bounties
steven-tey Aug 28, 2025
62dffb5
Merge branch 'main' into bounties
steven-tey Aug 28, 2025
5e8c3a6
improve `/bounties` endpoint latency
steven-tey Aug 29, 2025
dae7352
fix BountyProps vs BountyExtendedProps
steven-tey Aug 29, 2025
c270b8c
split out partner side types, totalCommission → totalCommissions
steven-tey Aug 29, 2025
8b9f30c
missed a spot
steven-tey Aug 29, 2025
998db26
BountySchema + BountyListSchema, getBountyWithDetails
steven-tey Aug 29, 2025
318b504
fix types
steven-tey Aug 29, 2025
b60afbe
onWheel={(e) => e.currentTarget.blur()}
steven-tey Aug 29, 2025
aa66a4c
final changes
steven-tey Aug 29, 2025
feaaeb0
only show group filter options that are part of the bounty
steven-tey Aug 29, 2025
ae07c6e
fix get available bounties for an enrolled program
devkiran Aug 29, 2025
47fc53e
Update bounty-action-button.tsx
devkiran Aug 29, 2025
b846182
Delete use-api-mutation.ts
devkiran Aug 29, 2025
c4c18d9
Update add-edit-bounty-sheet.tsx
devkiran Aug 29, 2025
9726b48
Update add-edit-bounty-sheet.tsx
devkiran Aug 29, 2025
606913c
add skipWorkflow
devkiran Aug 29, 2025
a690c59
Update route.ts
devkiran Aug 29, 2025
2e6f613
Update bounties.ts
devkiran Aug 29, 2025
591a849
Update integration.ts
devkiran Aug 29, 2025
1f11afd
Create index.test.ts
devkiran Aug 29, 2025
ce5fe0e
update BOUNTY_GROUP_ID, remove test.skip
steven-tey Aug 29, 2025
8ab47d0
Merge pull request #2786 from dubinc/bounties-updates
steven-tey Aug 29, 2025
1735ce6
Merge branch 'main' into bounties
steven-tey Aug 29, 2025
130d30d
return early if invalid groupIds
steven-tey Aug 29, 2025
5df2481
Check if bounty start date is at least 10 minutes in the past
devkiran Aug 29, 2025
a2d486d
small fix
devkiran Aug 29, 2025
081a0fc
simplify with notBefore, reenable email sending
steven-tey Aug 29, 2025
51f10f5
finalize bounties/notify-partners cron
steven-tey Aug 29, 2025
81fca53
Update bounty-action-button.tsx
steven-tey Aug 29, 2025
2cf55c0
add bounties to audit logs, finalize bounty response schema
steven-tey Aug 29, 2025
ce575ef
process a single page per invocation and re-enqueue next page via QStash
steven-tey Aug 29, 2025
b94d76d
generateBountyName + make bounty.name non null
steven-tey Aug 29, 2025
f69991e
Update add-edit-bounty-sheet.tsx
steven-tey Aug 29, 2025
53fe04c
fix bounty.name field type
steven-tey Aug 29, 2025
9394882
add bounty_submission.approved and rejected to audit logs, add View c…
steven-tey Aug 29, 2025
ba9c55b
final changes
steven-tey Aug 29, 2025
00c87ea
add bounty.deleted audit log, finalize tests
steven-tey Aug 30, 2025
e979bf7
final fixes (executeWorkflows, bounty_submission audit logs)
steven-tey Aug 30, 2025
bd43161
fix tests
steven-tey Aug 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
280 changes: 280 additions & 0 deletions apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log";
import { getBountyWithDetails } from "@/lib/api/bounties/get-bounty-with-details";
import { DubApiError } from "@/lib/api/errors";
import { throwIfInvalidGroupIds } from "@/lib/api/groups/throw-if-invalid-group-ids";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
import { qstash } from "@/lib/cron";
import { sendWorkspaceWebhook } from "@/lib/webhook/publish";
import {
BountySchema,
BountySchemaExtended,
updateBountySchema,
} from "@/lib/zod/schemas/bounties";
import { prisma } from "@dub/prisma";
import { APP_DOMAIN_WITH_NGROK, arrayEqual } from "@dub/utils";
import { PartnerGroup, Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";

// GET /api/bounties/[bountyId] - get a bounty
export const GET = withWorkspace(
async ({ workspace, params }) => {
const { bountyId } = params;

const programId = getDefaultProgramIdOrThrow(workspace);

const bounty = await getBountyWithDetails({
bountyId,
programId,
});

return NextResponse.json(BountySchemaExtended.parse(bounty));
},
{
requiredPlan: [
"business",
"business plus",
"business extra",
"business max",
"advanced",
"enterprise",
],
},
);

// PATCH /api/bounties/[bountyId] - update a bounty
export const PATCH = withWorkspace(
async ({ workspace, params, req, session }) => {
const { bountyId } = params;
const programId = getDefaultProgramIdOrThrow(workspace);

const {
name,
description,
startsAt,
endsAt,
rewardAmount,
submissionRequirements,
performanceCondition,
groupIds,
} = updateBountySchema.parse(await parseRequestBody(req));

if (startsAt && endsAt && endsAt < startsAt) {
throw new DubApiError({
message: "endsAt must be on or after startsAt.",
code: "bad_request",
});
}
const bounty = await prisma.bounty.findUniqueOrThrow({
where: {
id: bountyId,
programId,
},
include: {
groups: true,
},
});

// TODO:
// When we do archive, make sure it disables the workflow
Comment on lines +80 to +81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment indicates incomplete archive functionality that could leave workflows active when bounties are archived.

View Details

Analysis

The TODO comment on lines 79-80 states "When we do archive, make sure it disables the workflow". This indicates that the archive functionality is incomplete and could lead to workflows continuing to execute even after their associated bounties are archived.

This could cause several issues:

  1. Unwanted workflow executions: Performance-based bounties could continue to award commissions even when archived
  2. Data consistency problems: Partners might receive rewards for archived bounties
  3. Business logic violations: Archived bounties should be inactive

This TODO indicates production-ready functionality is missing. The workflow should be disabled/deleted when a bounty is archived, similar to how it's handled in the DELETE endpoint (lines 188-194).


// if groupIds is provided and is different from the current groupIds, update the groups
let updatedPartnerGroups: PartnerGroup[] | undefined = undefined;
if (
groupIds &&
!arrayEqual(
bounty.groups.map((group) => group.groupId),
groupIds,
)
) {
updatedPartnerGroups = await throwIfInvalidGroupIds({
programId,
groupIds,
});
}

const data = await prisma.$transaction(async (tx) => {
const updatedBounty = await tx.bounty.update({
where: {
id: bounty.id,
},
data: {
name: name ?? undefined,
description,
startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4)
endsAt,
rewardAmount,
...(bounty.type === "submission" &&
submissionRequirements !== undefined && {
submissionRequirements: submissionRequirements ?? Prisma.JsonNull,
}),
...(updatedPartnerGroups && {
groups: {
deleteMany: {},
create: updatedPartnerGroups.map((group) => ({
groupId: group.id,
})),
},
}),
},
include: {
workflow: true,
groups: true,
},
});

if (updatedBounty.workflowId && performanceCondition) {
await tx.workflow.update({
where: {
id: updatedBounty.workflowId,
},
data: {
triggerConditions: [performanceCondition],
},
});
}

return {
...updatedBounty,
performanceCondition,
};
});

const updatedBounty = BountySchema.parse({
...data,
groups: data.groups.map(({ groupId }) => ({ id: groupId })),
performanceCondition: data.workflow?.triggerConditions?.[0],
});

waitUntil(
Promise.allSettled([
recordAuditLog({
workspaceId: workspace.id,
programId,
action: "bounty.updated",
description: `Bounty ${bounty.id} updated`,
actor: session?.user,
targets: [
{
type: "bounty",
id: bounty.id,
metadata: updatedBounty,
},
],
}),
sendWorkspaceWebhook({
workspace,
trigger: "bounty.updated",
data: updatedBounty,
}),

// if bounty.startsAt was updated, publish a new message to the queue
updatedBounty.startsAt.getTime() !== bounty.startsAt.getTime() &&
qstash.publishJSON({
url: `${APP_DOMAIN_WITH_NGROK}/api/cron/bounties/notify-partners`,
body: {
bountyId: updatedBounty.id,
},
notBefore: Math.floor(updatedBounty.startsAt.getTime() / 1000),
}),
]),
);

return NextResponse.json(updatedBounty);
},
{
requiredPlan: [
"business",
"business plus",
"business extra",
"business max",
"advanced",
"enterprise",
],
},
);

// DELETE /api/bounties/[bountyId] - delete a bounty
export const DELETE = withWorkspace(
async ({ workspace, params, session }) => {
const { bountyId } = params;
const programId = getDefaultProgramIdOrThrow(workspace);

const bounty = await prisma.bounty.findUniqueOrThrow({
where: {
id: bountyId,
programId,
},
include: {
groups: true,
workflow: true,
_count: {
select: {
submissions: true,
},
},
},
});

if (bounty._count.submissions > 0) {
throw new DubApiError({
message:
"Bounties with submissions cannot be deleted. You can archive them instead.",
code: "bad_request",
});
}

await prisma.$transaction(async (tx) => {
const bounty = await tx.bounty.delete({
where: {
id: bountyId,
},
});

if (bounty.workflowId) {
await tx.workflow.delete({
where: {
id: bounty.workflowId,
},
});
}
});

const deletedBounty = BountySchema.parse({
...bounty,
groups: bounty.groups.map(({ groupId }) => ({ id: groupId })),
performanceCondition: bounty.workflow?.triggerConditions?.[0],
});

waitUntil(
recordAuditLog({
workspaceId: workspace.id,
programId,
action: "bounty.deleted",
description: `Bounty ${bountyId} deleted`,
actor: session?.user,
targets: [
{
type: "bounty",
id: bountyId,
metadata: deletedBounty,
},
],
}),
);

return NextResponse.json({ id: bountyId });
},
{
requiredPlan: [
"business",
"business plus",
"business extra",
"business max",
"advanced",
"enterprise",
],
},
);
Loading