-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add custom reward description to bounty #2833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
13835d8
5190ba2
41c84e3
3497627
f47c381
5e8155f
8f45149
f04ebc9
ea7c904
dc56b3e
90ed7b1
db46513
b801010
cef1d02
cd2ca8d
e2beca7
83f8b18
dd1c95d
d7947b7
c319d1a
b4504fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { recordAuditLog } from "@/lib/api/audit-logs/record-audit-log"; | ||
| import { generateBountyName } from "@/lib/api/bounties/generate-bounty-name"; | ||
| import { generatePerformanceBountyName } from "@/lib/api/bounties/generate-performance-bounty-name"; | ||
| 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"; | ||
|
|
@@ -57,17 +57,20 @@ export const PATCH = withWorkspace( | |
| startsAt, | ||
| endsAt, | ||
| rewardAmount, | ||
| rewardDescription, | ||
| submissionRequirements, | ||
| performanceCondition, | ||
| groupIds, | ||
| } = updateBountySchema.parse(await parseRequestBody(req)); | ||
|
|
||
| if (startsAt && endsAt && endsAt < startsAt) { | ||
| throw new DubApiError({ | ||
| message: "endsAt must be on or after startsAt.", | ||
| message: | ||
| "Bounty end date (endsAt) must be on or after start date (startsAt).", | ||
| code: "bad_request", | ||
| }); | ||
| } | ||
|
|
||
| const bounty = await prisma.bounty.findUniqueOrThrow({ | ||
| where: { | ||
| id: bountyId, | ||
|
|
@@ -78,6 +81,21 @@ export const PATCH = withWorkspace( | |
| }, | ||
| }); | ||
|
|
||
| if (rewardAmount === null || rewardAmount === 0) { | ||
| if (bounty.type === "performance") { | ||
| throw new DubApiError({ | ||
| code: "bad_request", | ||
| message: "Reward amount is required for performance bounties", | ||
| }); | ||
| } else if (!rewardDescription) { | ||
| throw new DubApiError({ | ||
| code: "bad_request", | ||
| message: | ||
| "For submission bounties, either reward amount or reward description is required", | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // TODO: | ||
| // When we do archive, make sure it disables the workflow | ||
|
|
||
|
|
@@ -96,23 +114,28 @@ export const PATCH = withWorkspace( | |
| }); | ||
| } | ||
|
|
||
| // Bounty name | ||
| let bountyName = name; | ||
|
|
||
| if (bounty.type === "performance" && performanceCondition) { | ||
| bountyName = generatePerformanceBountyName({ | ||
| rewardAmount: rewardAmount ?? 0, // this shouldn't happen since we return early if rewardAmount is null | ||
| condition: performanceCondition, | ||
| }); | ||
| } | ||
steven-tey marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Incomplete Validation Allows Undefined ValuesThe update bounty route's Additional Locations (1) |
||
|
|
||
| const data = await prisma.$transaction(async (tx) => { | ||
| const updatedBounty = await tx.bounty.update({ | ||
| where: { | ||
| id: bounty.id, | ||
| }, | ||
| data: { | ||
| name: | ||
| bounty.type === "performance" && rewardAmount | ||
| ? generateBountyName({ | ||
| rewardAmount, | ||
| condition: performanceCondition, | ||
| }) | ||
| : name ?? undefined, | ||
| name: bountyName ?? undefined, | ||
| description, | ||
| startsAt: startsAt!, // Can remove the ! when we're on a newer TS version (currently 5.4.4) | ||
| endsAt, | ||
| rewardAmount, | ||
| rewardDescription, | ||
| ...(bounty.type === "submission" && | ||
| submissionRequirements !== undefined && { | ||
| submissionRequirements: submissionRequirements ?? Prisma.DbNull, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.