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.

randomize sort for featured programs

Steven Teyf8ec544dbe36
diff --git a/apps/web/app/(ee)/api/network/programs/route.ts b/apps/web/app/(ee)/api/network/programs/route.ts
index dadc30462d..a9d0fed6c5 100644
--- a/apps/web/app/(ee)/api/network/programs/route.ts
+++ b/apps/web/app/(ee)/api/network/programs/route.ts
@@ -113,19 +113,23 @@ export const GET = withPartnerProfile(async ({ partner, searchParams }) => {
return NextResponse.json(
z.array(NetworkProgramSchema).parse(
- programs.map((program) => ({
- ...program,
- rewards:
- program.groups.length > 0
- ? [
- program.groups[0].clickReward,
- program.groups[0].leadReward,
- program.groups[0].saleReward,
- ].filter(Boolean)
- : [],
- discount: program.groups.length > 0 ? program.groups[0].discount : null,
- categories: program.categories.map(({ category }) => category),
- })),
+ programs
+ // if requesting featured programs, randomize the order
+ .sort(() => (featured ? Math.random() - 0.5 : 0))
+ .map((program) => ({
+ ...program,
+ rewards:
+ program.groups.length > 0
+ ? [
+ program.groups[0].clickReward,
+ program.groups[0].leadReward,
+ program.groups[0].saleReward,
+ ].filter(Boolean)
+ : [],
+ discount:
+ program.groups.length > 0 ? program.groups[0].discount : null,
+ categories: program.categories.map(({ category }) => category),
+ })),
),
);
});