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.

ACTIVE_ENROLLMENT_STATUSES

Steven Teyade5f5264b47
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 9ad3732eae..f6bf324815 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
@@ -2,6 +2,7 @@ import { createId } from "@/lib/api/create-id";
import { handleAndReturnErrorResponse } from "@/lib/api/errors";
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
+import { ACTIVE_ENROLLMENT_STATUSES } from "@/lib/zod/schemas/partners";
import { sendBatchEmail } from "@dub/email";
import NewBountyAvailable from "@dub/email/templates/new-bounty-available";
import { prisma } from "@dub/prisma";
@@ -93,7 +94,7 @@ export async function POST(req: Request) {
},
}),
status: {
- in: ["approved", "invited"],
+ in: ACTIVE_ENROLLMENT_STATUSES,
},
partner: {
email: {
diff --git a/apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts b/apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts
index 5ff228e432..2ffe979841 100644
--- a/apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts
+++ b/apps/web/app/(ee)/api/cron/campaigns/broadcast/route.ts
@@ -5,6 +5,7 @@ import { renderCampaignEmailHTML } from "@/lib/api/workflows/render-campaign-ema
import { qstash } from "@/lib/cron";
import { verifyQstashSignature } from "@/lib/cron/verify-qstash";
import { TiptapNode } from "@/lib/types";
+import { ACTIVE_ENROLLMENT_STATUSES } from "@/lib/zod/schemas/partners";
import { sendBatchEmail } from "@dub/email";
import CampaignEmail from "@dub/email/templates/campaign-email";
import { prisma } from "@dub/prisma";
@@ -142,7 +143,9 @@ export async function POST(req: Request) {
const programEnrollments = await prisma.programEnrollment.findMany({
where: {
programId: campaign.programId,
- status: "approved",
+ status: {
+ in: ACTIVE_ENROLLMENT_STATUSES,
+ },
...(campaignGroupIds.length > 0 && {
groupId: {
in: campaignGroupIds,
diff --git a/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts b/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts
index cfe9198c22..6957cd1326 100644
--- a/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts
+++ b/apps/web/app/(ee)/api/partners/[partnerId]/cross-program-summary/route.ts
@@ -1,7 +1,10 @@
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";
import { withWorkspace } from "@/lib/auth";
-import { partnerCrossProgramSummarySchema } from "@/lib/zod/schemas/partners";
+import {
+ ACTIVE_ENROLLMENT_STATUSES,
+ partnerCrossProgramSummarySchema,
+} from "@/lib/zod/schemas/partners";
import { prisma } from "@dub/prisma";
import { NextResponse } from "next/server";
@@ -39,7 +42,7 @@ export const GET = withWorkspace(
// approved and archived statuses
const trustedPrograms = programEnrollments
.filter((enrollment) =>
- ["approved", "archived"].includes(enrollment.status),
+ ACTIVE_ENROLLMENT_STATUSES.includes(enrollment.status),
)
.reduce((acc, enrollment) => acc + enrollment._count, 0);
diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.ts
index 8ece606c55..a67b5e4a70 100644
--- a/apps/web/lib/zod/schemas/partners.ts
+++ b/apps/web/lib/zod/schemas/partners.ts
@@ -24,6 +24,11 @@ import { parseUrlSchema } from "./utils";
export const PARTNERS_MAX_PAGE_SIZE = 100;
+export const ACTIVE_ENROLLMENT_STATUSES: ProgramEnrollmentStatus[] = [
+ "approved",
+ "archived",
+];
+
export const INACTIVE_ENROLLMENT_STATUSES: ProgramEnrollmentStatus[] = [
"banned",
"deactivated",
diff --git a/apps/web/scripts/convert-case-sensitive.ts b/apps/web/scripts/convert-case-sensitive.ts
index 0a295f42f6..3c6c236252 100644
--- a/apps/web/scripts/convert-case-sensitive.ts
+++ b/apps/web/scripts/convert-case-sensitive.ts
@@ -15,44 +15,54 @@ async function main() {
},
};
- const links = await prisma.link.findMany({
- where,
- orderBy: {
- createdAt: "desc",
- },
- take: 100,
- });
-
- const remainingLinks = await prisma.link.count({
- where,
- skip: 100,
- });
-
- console.log(`Remaining links: ${remainingLinks}`);
-
- await Promise.all(
- links.map(async (link) => {
- const newKey = encodeKeyIfCaseSensitive({
- domain: link.domain,
- key: link.key,
- });
-
- const newLink = await prisma.link.update({
- where: { id: link.id },
- data: {
- key: newKey,
- shortLink: linkConstructorSimple({
- domain: link.domain,
- key: newKey,
- }),
- },
- });
-
- console.log(
- `Updated link ${link.id} from key ${link.key} to ${newLink.key} (shortLink: ${newLink.shortLink})`,
- );
- }),
- );
+ while (true) {
+ const links = await prisma.link.findMany({
+ where,
+ orderBy: {
+ createdAt: "desc",
+ },
+ take: 100,
+ });
+ if (!links.length) {
+ console.log("No more links to convert.");
+ break;
+ }
+
+ await Promise.all(
+ links.map(async (link) => {
+ const newKey = encodeKeyIfCaseSensitive({
+ domain: link.domain,
+ key: link.key,
+ });
+
+ try {
+ const newLink = await prisma.link.update({
+ where: { id: link.id },
+ data: {
+ key: newKey,
+ shortLink: linkConstructorSimple({
+ domain: link.domain,
+ key: newKey,
+ }),
+ },
+ });
+
+ console.log(
+ `Updated link ${link.id} from key ${link.key} to ${newLink.key} (shortLink: ${newLink.shortLink})`,
+ );
+ } catch (error) {
+ console.error(`Error updating link ${link.id}: ${error}`);
+ }
+ }),
+ );
+
+ const remainingLinks = await prisma.link.count({
+ where,
+ skip: 100,
+ });
+
+ console.log(`Remaining links: ${remainingLinks}`);
+ }
}
main();