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.

final changes

Steven Tey51e0acb9a049
diff --git a/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts b/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
index b1ab351e24..34e145939b 100644
--- a/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
+++ b/apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
@@ -125,7 +125,9 @@ export async function POST(req: Request) {
);
}
- console.log("programEnrollments", programEnrollments);
+ console.log(
+ `Found ${programEnrollments.length} program enrollments eligible for bounty ${bountyId}.`,
+ );
// Find the workflow condition
const condition = z
@@ -141,19 +143,27 @@ export async function POST(req: Request) {
};
});
- const bountySubmissions = partners.map((partner) => ({
- id: createId({ prefix: "bnty_sub_" }),
- programId: bounty.programId,
- partnerId: partner.id,
- bountyId: bounty.id,
- performanceCount: partner[condition.attribute] ?? 0,
- }));
+ const bountySubmissionsToCreate = partners
+ // only create submissions for partners that have at least 1 performanceCount
+ .filter((partner) => partner[condition.attribute] > 0)
+ .map((partner) => ({
+ id: createId({ prefix: "bnty_sub_" }),
+ programId: bounty.programId,
+ partnerId: partner.id,
+ bountyId: bounty.id,
+ performanceCount: partner[condition.attribute],
+ }));
+
+ console.table(bountySubmissionsToCreate);
// Create bounty submissions
- await prisma.bountySubmission.createMany({
- data: bountySubmissions,
+ const createdBountySubmissions = await prisma.bountySubmission.createMany({
+ data: bountySubmissionsToCreate,
skipDuplicates: true,
});
+ console.log(
+ `Created ${createdBountySubmissions.count} bounty submissions for bounty ${bountyId}.`,
+ );
if (programEnrollments.length === MAX_PAGE_SIZE) {
const response = await qstash.publishJSON({
@@ -171,7 +181,7 @@ export async function POST(req: Request) {
}
return logAndRespond(
- `Finished creating submissions for ${programEnrollments.length} partners for bounty ${bountyId}.`,
+ `Finished creating submissions for ${createdBountySubmissions.count} partners for bounty ${bountyId}.`,
);
} catch (error) {
await log({
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index eda8fc432d..0d485340cd 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -72,6 +72,7 @@ export const createBountySchema = z.object({
export const updateBountySchema = createBountySchema
.omit({
+ // omit fields that cannot be updated after creation
type: true,
performanceScope: true,
})
@@ -94,9 +95,9 @@ export const BountySchema = z.object({
rewardAmount: z.number().nullable(),
rewardDescription: z.string().nullable(),
performanceCondition: workflowConditionSchema.nullable().default(null),
+ performanceScope: z.nativeEnum(BountyPerformanceScope).nullable(),
submissionRequirements: submissionRequirementsSchema.nullable().default(null),
groups: z.array(GroupSchema.pick({ id: true })),
- performanceScope: z.nativeEnum(BountyPerformanceScope).nullable(),
});
export const getBountiesQuerySchema = z.object({
diff --git a/packages/prisma/client.ts b/packages/prisma/client.ts
index d97159a1cc..81766f1178 100644
--- a/packages/prisma/client.ts
+++ b/packages/prisma/client.ts
@@ -1,6 +1,7 @@
export * from "@prisma/client";
export {
+ BountyPerformanceScope,
BountySubmissionRejectionReason,
BountySubmissionStatus,
BountyType,