monthly earning users
This commit is contained in:
parent
f024cd39a2
commit
2c749dd07f
|
@ -33,6 +33,21 @@ export default {
|
|||
WHERE date_trunc('month', now_utc()) <> date_trunc('month', created_at)
|
||||
GROUP BY time
|
||||
ORDER BY time ASC`)
|
||||
},
|
||||
earnedGrowth: async (parent, args, { models }) => {
|
||||
return await models.$queryRaw(
|
||||
`SELECT time, count(distinct user_id) as num
|
||||
FROM
|
||||
((SELECT date_trunc('month', "ItemAct".created_at) AS time, "Item"."userId" as user_id
|
||||
FROM "ItemAct"
|
||||
JOIN "Item" on "ItemAct"."itemId" = "Item".id AND "Item"."userId" <> "ItemAct"."userId"
|
||||
WHERE date_trunc('month', now_utc()) <> date_trunc('month', "ItemAct".created_at))
|
||||
UNION ALL
|
||||
(SELECT date_trunc('month', created_at) AS time, "userId" as user_id
|
||||
FROM "Earn"
|
||||
WHERE date_trunc('month', now_utc()) <> date_trunc('month', created_at))) u
|
||||
GROUP BY time
|
||||
ORDER BY time ASC`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ export default gql`
|
|||
activeGrowth: [TimeNum!]!
|
||||
itemGrowth: [TimeNum!]!
|
||||
spentGrowth: [TimeNum!]!
|
||||
earnedGrowth: [TimeNum!]!
|
||||
}
|
||||
|
||||
type TimeNum {
|
||||
|
|
|
@ -24,14 +24,20 @@ export const getServerSideProps = getGetServerSideProps(
|
|||
time
|
||||
num
|
||||
}
|
||||
earnedGrowth {
|
||||
time
|
||||
num
|
||||
}
|
||||
}`)
|
||||
|
||||
const dateFormatter = timeStr => {
|
||||
const date = new Date(timeStr)
|
||||
return `${('0' + (date.getMonth() + 1)).slice(-2)}/${String(date.getFullYear()).slice(-2)}`
|
||||
return `${('0' + (date.getMonth() + 2)).slice(-2)}/${String(date.getFullYear()).slice(-2)}`
|
||||
}
|
||||
|
||||
export default function Growth ({ data: { registrationGrowth, activeGrowth, itemGrowth, spentGrowth } }) {
|
||||
export default function Growth ({
|
||||
data: { registrationGrowth, activeGrowth, itemGrowth, spentGrowth, earnedGrowth }
|
||||
}) {
|
||||
return (
|
||||
<Layout>
|
||||
<Row className='mt-3'>
|
||||
|
@ -50,6 +56,12 @@ export default function Growth ({ data: { registrationGrowth, activeGrowth, item
|
|||
<GrowthLineChart data={spentGrowth} xName='month' yName='sats spent' />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row className='mt-3'>
|
||||
<Col>
|
||||
<GrowthLineChart data={earnedGrowth} xName='month' yName='earning users' />
|
||||
</Col>
|
||||
<Col />
|
||||
</Row>
|
||||
</Layout>
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue