Skip to content

Commit

Permalink
Prioritize users in watch all
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Dec 24, 2024
1 parent 2111ba8 commit 8949337
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions apps/web/app/api/google/watch/all/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,24 @@ async function watchAllEmails() {
},
});

const users = premiums.flatMap((premium) =>
premium.users.map((user) => ({ ...user, premium })),
);
const users = premiums
.flatMap((premium) => premium.users.map((user) => ({ ...user, premium })))
.sort((a, b) => {
// Prioritize null dates first
if (!a.watchEmailsExpirationDate && b.watchEmailsExpirationDate)
return -1;
if (a.watchEmailsExpirationDate && !b.watchEmailsExpirationDate) return 1;

// If both have dates, sort by earliest date first
if (a.watchEmailsExpirationDate && b.watchEmailsExpirationDate) {
return (
new Date(a.watchEmailsExpirationDate).getTime() -
new Date(b.watchEmailsExpirationDate).getTime()
);
}

return 0;
});

console.log(`Watching emails for ${users.length} users`);

Expand Down

1 comment on commit 8949337

@vercel
Copy link

@vercel vercel bot commented on 8949337 Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.