diff --git a/api/resolvers/rewards.js b/api/resolvers/rewards.js index 646c5195..9f833eb9 100644 --- a/api/resolvers/rewards.js +++ b/api/resolvers/rewards.js @@ -49,9 +49,25 @@ async function getActiveRewards (models) { ) u` } +async function getMonthlyRewards (when, models) { + return await models.$queryRaw` + SELECT + (sum(total) / 1000)::INT as total, + date_trunc('month', ${when?.[0]}::text::timestamp) AT TIME ZONE 'America/Chicago' as time, + json_build_array( + json_build_object('name', 'donations', 'value', (sum(donations) / 1000)::INT), + json_build_object('name', 'fees', 'value', (sum(fees) / 1000)::INT), + json_build_object('name', 'boost', 'value', (sum(boost) / 1000)::INT), + json_build_object('name', 'jobs', 'value', (sum(jobs) / 1000)::INT), + json_build_object('name', 'anon''s stack', 'value', (sum(anons_stack) / 1000)::INT) + ) AS sources + FROM rewards_days + WHERE date_trunc('month', rewards_days.t) = date_trunc('month', ${when?.[0]}::text::timestamp - interval '1 month')` +} + async function getRewards (when, models) { if (when) { - if (when.length > 2) { + if (when.length > 1) { throw new GraphQLError('too many dates', { extensions: { code: 'BAD_USER_INPUT' } }) } when.forEach(w => { @@ -62,6 +78,10 @@ async function getRewards (when, models) { if (new Date(when[0]) > new Date(when[when.length - 1])) { throw new GraphQLError('bad date range', { extensions: { code: 'BAD_USER_INPUT' } }) } + + if (new Date(when[0]).getTime() >= new Date('2024-03-01').getTime()) { + return await getMonthlyRewards(when, models) + } } const results = await models.$queryRaw` diff --git a/components/notifications.js b/components/notifications.js index 529d4bcf..01f50408 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -165,7 +165,7 @@ function EarnNotification ({ n }) { {n.sources.tipComments > 0 && {(n.sources.comments > 0 || n.sources.posts > 0 || n.sources.tipPosts > 0) && ' \\ '}{numWithUnits(n.sources.tipComments, { abbreviate: false })} for zapping top comments early} }