Skip to content

Commit f8ec544

Browse files
committed
randomize sort for featured programs
1 parent 70567c7 commit f8ec544

File tree

1 file changed

+17
-13
lines changed
  • apps/web/app/(ee)/api/network/programs

1 file changed

+17
-13
lines changed

apps/web/app/(ee)/api/network/programs/route.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,23 @@ export const GET = withPartnerProfile(async ({ partner, searchParams }) => {
113113

114114
return NextResponse.json(
115115
z.array(NetworkProgramSchema).parse(
116-
programs.map((program) => ({
117-
...program,
118-
rewards:
119-
program.groups.length > 0
120-
? [
121-
program.groups[0].clickReward,
122-
program.groups[0].leadReward,
123-
program.groups[0].saleReward,
124-
].filter(Boolean)
125-
: [],
126-
discount: program.groups.length > 0 ? program.groups[0].discount : null,
127-
categories: program.categories.map(({ category }) => category),
128-
})),
116+
programs
117+
// if requesting featured programs, randomize the order
118+
.sort(() => (featured ? Math.random() - 0.5 : 0))
119+
.map((program) => ({
120+
...program,
121+
rewards:
122+
program.groups.length > 0
123+
? [
124+
program.groups[0].clickReward,
125+
program.groups[0].leadReward,
126+
program.groups[0].saleReward,
127+
].filter(Boolean)
128+
: [],
129+
discount:
130+
program.groups.length > 0 ? program.groups[0].discount : null,
131+
categories: program.categories.map(({ category }) => category),
132+
})),
129133
),
130134
);
131135
});

0 commit comments

Comments
 (0)