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 bounty.deleted audit log, finalize tests

Steven Tey00c87ea73749
diff --git a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
index 47a6aa7390..f2555cac01 100644
--- a/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
+++ b/apps/web/app/(ee)/api/bounties/[bountyId]/route.ts
@@ -198,7 +198,7 @@ export const PATCH = withWorkspace(
// DELETE /api/bounties/[bountyId] - delete a bounty
export const DELETE = withWorkspace(
- async ({ workspace, params }) => {
+ async ({ workspace, params, session }) => {
const { bountyId } = params;
const programId = getDefaultProgramIdOrThrow(workspace);
@@ -208,6 +208,8 @@ export const DELETE = withWorkspace(
programId,
},
include: {
+ groups: true,
+ workflow: true,
_count: {
select: {
submissions: true,
@@ -240,6 +242,29 @@ export const DELETE = withWorkspace(
}
});
+ 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 });
},
{
diff --git a/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts b/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts
index 0d31710117..0c803bd4c8 100644
--- a/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts
+++ b/apps/web/app/(ee)/api/cron/bounties/notify-partners/route.ts
@@ -59,6 +59,11 @@ export async function POST(req: Request) {
// Find groupIds
const groupIds = bounty.groups.map(({ groupId }) => groupId);
+ console.log(
+ `Bounty ${bountyId} is applicable to ${
+ groupIds.length === 0 ? "all" : groupIds.length
+ } groups (groupIds: ${JSON.stringify(groupIds)})`,
+ );
const programEnrollments = await prisma.programEnrollment.findMany({
where: {
diff --git a/apps/web/tests/bounties/index.test.ts b/apps/web/tests/bounties/index.test.ts
index b31aed7d7e..5ac7e95541 100644
--- a/apps/web/tests/bounties/index.test.ts
+++ b/apps/web/tests/bounties/index.test.ts
@@ -72,6 +72,24 @@ describe.sequential("/bounties/**", async () => {
bountyId = bounty.id;
});
+ test("POST /bounties - invalid group IDs", async () => {
+ const { status, data } = await http.post({
+ path: "/bounties",
+ body: {
+ ...submissionBounty,
+ groupIds: ["invalid-group-id"],
+ },
+ });
+
+ expect(status).toEqual(400);
+ expect(data).toMatchObject({
+ error: {
+ message: "Invalid group IDs detected: invalid-group-id",
+ code: "bad_request",
+ },
+ });
+ });
+
test("GET /bounties/{bountyId}", async () => {
const { status, data: bounty } = await http.get<Bounty>({
path: `/bounties/${bountyId}`,