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.

address CR feedbac

Steven Tey3e590d90c21b
diff --git a/apps/web/lib/api/partners/upsert-imported-program-enrollment.ts b/apps/web/lib/api/partners/upsert-imported-program-enrollment.ts
index 99b6e4d266..6f543fd993 100644
--- a/apps/web/lib/api/partners/upsert-imported-program-enrollment.ts
+++ b/apps/web/lib/api/partners/upsert-imported-program-enrollment.ts
@@ -48,7 +48,13 @@ export async function upsertImportedProgramEnrollment<
}
const enrollment = await prisma.programEnrollment.upsert({
- where,
+ where: {
+ ...where,
+ // to account for race conditions
+ status: {
+ not: "banned",
+ },
+ },
create,
update: {
status: "approved",
diff --git a/apps/web/scripts/partners/restore-reopened-bans.ts b/apps/web/scripts/partners/restore-reopened-bans.ts
index 368522e8c1..e0c5a2644e 100644
--- a/apps/web/scripts/partners/restore-reopened-bans.ts
+++ b/apps/web/scripts/partners/restore-reopened-bans.ts
@@ -1,9 +1,9 @@
-import { linkCache } from "@/lib/api/links/cache";
-import { queuePartnerSearchSync } from "@/lib/api/partners/queue-partner-search-sync";
import { prisma } from "@/lib/prisma";
import { chunk } from "@dub/utils";
import { Prisma, ProgramEnrollmentStatus } from "@prisma/client";
import "dotenv-flow/config";
+import { linkCache } from "../../lib/api/links/cache";
+import { queuePartnerSearchSync } from "../../lib/api/partners/queue-partner-search-sync";
// A re-import set these enrollments back to approved and left bannedAt in
// place. A real unban clears bannedAt. Deactivated enrollments are left as-is.
@@ -41,29 +41,6 @@ async function main() {
for (const batch of chunk(enrollments, BATCH_SIZE)) {
const ids = batch.map((enrollment) => enrollment.id);
- const { count } = await prisma.programEnrollment.updateMany({
- where: {
- id: {
- in: ids,
- },
- bannedAt: {
- not: null,
- },
- status: ProgramEnrollmentStatus.approved,
- },
- data: {
- status: ProgramEnrollmentStatus.banned,
- clickRewardId: null,
- leadRewardId: null,
- saleRewardId: null,
- referralRewardId: null,
- customRewardId: null,
- discountId: null,
- },
- });
-
- restored += count;
-
const partnerIdsByProgramId = new Map<string, string[]>();
for (const enrollment of batch) {
@@ -109,6 +86,29 @@ async function main() {
console.log(`Disabled ${links.length} links in program ${programId}.`);
}
+ const { count } = await prisma.programEnrollment.updateMany({
+ where: {
+ id: {
+ in: ids,
+ },
+ bannedAt: {
+ not: null,
+ },
+ status: ProgramEnrollmentStatus.approved,
+ },
+ data: {
+ status: ProgramEnrollmentStatus.banned,
+ clickRewardId: null,
+ leadRewardId: null,
+ saleRewardId: null,
+ referralRewardId: null,
+ customRewardId: null,
+ discountId: null,
+ },
+ });
+
+ restored += count;
+
await queuePartnerSearchSync({
enrollmentIds: ids,
});