add anon's earnings to reward pool
This commit is contained in:
parent
03f0329984
commit
15c11efc0a
|
@ -1,6 +1,7 @@
|
||||||
import { GraphQLError } from 'graphql'
|
import { GraphQLError } from 'graphql'
|
||||||
import { amountSchema, ssValidate } from '../../lib/validate'
|
import { amountSchema, ssValidate } from '../../lib/validate'
|
||||||
import serialize from './serial'
|
import serialize from './serial'
|
||||||
|
import { ANON_USER_ID } from '../../lib/constants'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
Query: {
|
Query: {
|
||||||
|
@ -8,9 +9,10 @@ export default {
|
||||||
const [result] = await models.$queryRaw`
|
const [result] = await models.$queryRaw`
|
||||||
SELECT coalesce(FLOOR(sum(sats)), 0) as total, json_build_array(
|
SELECT coalesce(FLOOR(sum(sats)), 0) as total, json_build_array(
|
||||||
json_build_object('name', 'donations', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'DONATION')), 0)),
|
json_build_object('name', 'donations', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'DONATION')), 0)),
|
||||||
json_build_object('name', 'fees', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type NOT IN ('BOOST', 'STREAM', 'DONATION'))), 0)),
|
json_build_object('name', 'fees', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type NOT IN ('BOOST', 'STREAM', 'DONATION', 'ANON'))), 0)),
|
||||||
json_build_object('name', 'boost', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'BOOST')), 0)),
|
json_build_object('name', 'boost', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'BOOST')), 0)),
|
||||||
json_build_object('name', 'jobs', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'STREAM')), 0))
|
json_build_object('name', 'jobs', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'STREAM')), 0)),
|
||||||
|
json_build_object('name', 'anon earnings', 'value', coalesce(FLOOR(sum(sats) FILTER(WHERE type = 'ANON')), 0))
|
||||||
) AS sources
|
) AS sources
|
||||||
FROM (
|
FROM (
|
||||||
(SELECT ("ItemAct".msats - COALESCE("ReferralAct".msats, 0)) / 1000.0 as sats, act::text as type
|
(SELECT ("ItemAct".msats - COALESCE("ReferralAct".msats, 0)) / 1000.0 as sats, act::text as type
|
||||||
|
@ -21,6 +23,12 @@ export default {
|
||||||
(SELECT sats::FLOAT, 'DONATION' as type
|
(SELECT sats::FLOAT, 'DONATION' as type
|
||||||
FROM "Donation"
|
FROM "Donation"
|
||||||
WHERE date_trunc('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = date_trunc('day', now() AT TIME ZONE 'America/Chicago'))
|
WHERE date_trunc('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = date_trunc('day', now() AT TIME ZONE 'America/Chicago'))
|
||||||
|
UNION ALL
|
||||||
|
(SELECT "ItemAct".msats / 1000.0 as sats, 'ANON' as type
|
||||||
|
FROM "Item"
|
||||||
|
JOIN "ItemAct" ON "ItemAct"."itemId" = "Item".id
|
||||||
|
WHERE "Item"."userId" = ${ANON_USER_ID} AND "ItemAct".act = 'TIP' AND "Item"."fwdUserId" IS NULL
|
||||||
|
AND date_trunc('day', "ItemAct".created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = date_trunc('day', now() AT TIME ZONE 'America/Chicago'))
|
||||||
) subquery`
|
) subquery`
|
||||||
|
|
||||||
return result || { total: 0, sources: [] }
|
return result || { total: 0, sources: [] }
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
const serialize = require('../api/resolvers/serial')
|
const serialize = require('../api/resolvers/serial')
|
||||||
|
const { ANON_USER_ID } = require('../lib/constants')
|
||||||
|
|
||||||
// const ITEM_EACH_REWARD = 3.0
|
// const ITEM_EACH_REWARD = 3.0
|
||||||
// const UPVOTE_EACH_REWARD = 6.0
|
// const UPVOTE_EACH_REWARD = 6.0
|
||||||
|
@ -22,6 +23,12 @@ function earn ({ models }) {
|
||||||
(SELECT sats * 1000 as msats
|
(SELECT sats * 1000 as msats
|
||||||
FROM "Donation"
|
FROM "Donation"
|
||||||
WHERE date_trunc('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = date_trunc('day', (now() - interval '1 day') AT TIME ZONE 'America/Chicago'))
|
WHERE date_trunc('day', created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = date_trunc('day', (now() - interval '1 day') AT TIME ZONE 'America/Chicago'))
|
||||||
|
UNION ALL
|
||||||
|
(SELECT "ItemAct".msats
|
||||||
|
FROM "Item"
|
||||||
|
JOIN "ItemAct" ON "ItemAct"."itemId" = "Item".id
|
||||||
|
WHERE "Item"."userId" = ${ANON_USER_ID} AND "ItemAct".act = 'TIP' AND "Item"."fwdUserId" IS NULL
|
||||||
|
AND date_trunc('day', "ItemAct".created_at AT TIME ZONE 'UTC' AT TIME ZONE 'America/Chicago') = date_trunc('day', (now() - interval '1 day') AT TIME ZONE 'America/Chicago'))
|
||||||
) subquery`
|
) subquery`
|
||||||
|
|
||||||
// XXX primsa will return a Decimal (https://mikemcl.github.io/decimal.js)
|
// XXX primsa will return a Decimal (https://mikemcl.github.io/decimal.js)
|
||||||
|
|
Loading…
Reference in New Issue