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.

Keep soft-deleted tags out of the list hydration

Rafibf2bc969999f
diff --git a/apps/web/lib/api/partners/get-partners.ts b/apps/web/lib/api/partners/get-partners.ts
index 2af57657d6..12db87c3aa 100644
--- a/apps/web/lib/api/partners/get-partners.ts
+++ b/apps/web/lib/api/partners/get-partners.ts
@@ -73,6 +73,13 @@ export async function getPartners(
},
},
programPartnerTags: {
+ // A deleted tag keeps its associations until the cleanup job removes
+ // them, and is recognizable only by its null programId
+ where: {
+ partnerTag: {
+ programId,
+ },
+ },
include: {
partnerTag: true,
},
diff --git a/apps/web/tests/partners/get-partners-search.test.ts b/apps/web/tests/partners/get-partners-search.test.ts
index fe25f2d19c..2d53955e6e 100644
--- a/apps/web/tests/partners/get-partners-search.test.ts
+++ b/apps/web/tests/partners/get-partners-search.test.ts
@@ -76,6 +76,29 @@ describe("getPartners search", () => {
);
});
+ it("hydrates only tags that still belong to the program", async () => {
+ // Deleting a tag nulls its programId first and removes the associations
+ // in a later job, so the relation must filter on the tag, not the link.
+ mocks.findMany.mockResolvedValue([enrollment("pge_1", "pn_1")]);
+
+ await getPartners(
+ {
+ programId: "prog_test",
+ page: 1,
+ pageSize: 25,
+ sortBy: "totalSaleAmount",
+ sortOrder: "desc",
+ },
+ { searchProvider: null },
+ );
+
+ const { include } = mocks.findMany.mock.calls.at(-1)![0];
+ expect(include.programPartnerTags).toEqual({
+ where: { partnerTag: { programId: "prog_test" } },
+ include: { partnerTag: true },
+ });
+ });
+
it("keeps a tenant filter on the database search path", async () => {
// tenantId predates the search provider, so `tenantId` + `search` still
// resolves entirely in the database rather than inheriting the candidate