diff --git a/backend/src/business/email/templates/ReviewQueueStaleTemplate.ts b/backend/src/business/email/templates/ReviewQueueStaleTemplate.ts index b4ba30dd..772c4edb 100644 --- a/backend/src/business/email/templates/ReviewQueueStaleTemplate.ts +++ b/backend/src/business/email/templates/ReviewQueueStaleTemplate.ts @@ -5,6 +5,7 @@ import Senders from './Senders'; type StoryEmailTemplateData = { storiesCount: number; reviewStoriesUrl: string; + stats: { reviewer: string; count: number }[]; }; class ReviewQueueStaleTemplate extends EmailTemplate< diff --git a/backend/src/cron/checkStaleStories.ts b/backend/src/cron/checkStaleStories.ts index b2ba4f7e..e4015137 100644 --- a/backend/src/cron/checkStaleStories.ts +++ b/backend/src/cron/checkStaleStories.ts @@ -14,6 +14,16 @@ function forgeReviewStoriesUrl(): string { return storyEditUrl.toString(); } +async function getReviewerStats(): Promise< + { reviewer: string; count: number }[] +> { + const stats = (await StoryRepository().query( + `select last_reviewer as reviewer, count(*) as count from stories where last_reviewer is not null group by last_reviewer order by count(*) desc;` + )) as Promise<{ reviewer: string; count: number }[]>; + console.log(stats); + return stats; +} + export default async function checkStaleStories(): Promise { const hasStaleStories = (await StoryRepository() @@ -34,10 +44,13 @@ export default async function checkStaleStories(): Promise { const reviewStoriesUrl = forgeReviewStoriesUrl(); + const stats = await getReviewerStats(); + const email = ReviewQueueStaleTemplate.createTemplatedEmail({ templateContext: { reviewStoriesUrl, storiesCount, + stats, }, metadata: {}, to: process.env.MODERATORS_TO_EMAIL ?? '',