The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Order by matching industry interests
Tim Wilson83c5b2828b08
diff --git a/apps/web/app/(ee)/api/network/partners/route.ts b/apps/web/app/(ee)/api/network/partners/route.tsindex 4a8cdbca0c..0909615586 100644--- a/apps/web/app/(ee)/api/network/partners/route.ts+++ b/apps/web/app/(ee)/api/network/partners/route.ts@@ -17,20 +17,25 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {const programId = getDefaultProgramIdOrThrow(workspace);- const { partnerNetworkEnabledAt } = await prisma.program.findUniqueOrThrow({- select: {- partnerNetworkEnabledAt: true,- },+ const program = await prisma.program.findUniqueOrThrow({where: {id: programId,},+ include: {+ industryInterests: true,+ },});- if (!partnerNetworkEnabledAt)++ if (!program.partnerNetworkEnabledAt)throw new DubApiError({code: "forbidden",message: "Partner network is not enabled for this program.",});+ const programIndustryInterests = program.industryInterests.map(+ (interest) => interest.industryInterest,+ );+const {partnerIds,status,@@ -57,7 +62,13 @@ export const GET = withWorkspace(casewhen pe.status = 'approved' then pe.createdAtelse null- end as recruitedAt+ end as recruitedAt,+ -- Match score based on number of matching industry interests+ ${+ programIndustryInterests.length > 0+ ? Prisma.sql`(SELECT COUNT(1) FROM PartnerIndustryInterest WHERE partnerId = p.id AND industryInterest IN (${Prisma.join(programIndustryInterests)})) as matchScore`+ : Prisma.sql`0 as matchScore`+ }FROMPartner p-- Any associated program enrollment@@ -109,7 +120,7 @@ export const GET = withWorkspace(${industryInterests && industryInterests.length > 0 ? Prisma.sql`AND EXISTS (SELECT 1 FROM PartnerIndustryInterest WHERE partnerId = p.id AND industryInterest IN (${Prisma.join(industryInterests)}))` : Prisma.sql``}${salesChannels && salesChannels.length > 0 ? Prisma.sql`AND EXISTS (SELECT 1 FROM PartnerSalesChannel WHERE partnerId = p.id AND salesChannel IN (${Prisma.join(salesChannels)}))` : Prisma.sql``}${preferredEarningStructures && preferredEarningStructures.length > 0 ? Prisma.sql`AND EXISTS (SELECT 1 FROM PartnerPreferredEarningStructure WHERE partnerId = p.id AND preferredEarningStructure IN (${Prisma.join(preferredEarningStructures)}))` : Prisma.sql``}- ORDER BY ${starred === true ? Prisma.sql`dp.starredAt DESC,` : Prisma.sql``} metrics.conversionRate DESC+ ORDER BY ${starred === true ? Prisma.sql`dp.starredAt DESC,` : Prisma.sql``} matchScore DESC, metrics.conversionRate DESCLIMIT ${pageSize} OFFSET ${(page - 1) * pageSize}`) satisfies Array<any>;return NextResponse.json(diff --git a/packages/prisma/schema/program.prisma b/packages/prisma/schema/program.prismaindex b73deb67cb..0513d1d78c 100644--- a/packages/prisma/schema/program.prisma+++ b/packages/prisma/schema/program.prisma@@ -76,6 +76,7 @@ model Program {comments PartnerComment[]campaigns Campaign[]discoveredPartners DiscoveredPartner[]+ industryInterests ProgramIndustryInterest[]@@index(workspaceId)@@index(domain)@@ -147,3 +148,13 @@ model ProgramApplication {@@index(groupId)@@index(email)}++model ProgramIndustryInterest {+ programId String+ industryInterest IndustryInterest++ program Program @relation(fields: [programId], references: [id], onDelete: Cascade)++ @@unique([programId, industryInterest])+ @@index(programId)+}\ No newline at end of file