Skip to content

Commit

Permalink
Add end/to dates for PAST time periods (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavlrsn authored Jan 11, 2023
1 parent 665f934 commit dc4871a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
32 changes: 24 additions & 8 deletions lib/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { gql } from '@apollo/client';
export const accountsQuery = gql`
query SearchAccounts(
$host: [AccountReferenceInput]
$quarterAgo: DateTime
$yearAgo: DateTime
$quarterFrom: DateTime
$quarterTo: DateTime
$yearFrom: DateTime
$yearTo: DateTime
$currency: Currency
$limit: Int
$offset: Int
Expand Down Expand Up @@ -45,13 +47,20 @@ export const accountsQuery = gql`
}
PAST_YEAR: stats {
contributorsCount(includeChildren: true, dateFrom: $yearAgo)
totalAmountSpent(net: true, includeChildren: true, dateFrom: $yearAgo, currency: $currency) {
contributorsCount(includeChildren: true, dateFrom: $yearFrom, dateTo: $yearTo)
totalAmountSpent(
net: true
includeChildren: true
dateFrom: $yearFrom
dateTo: $yearTo
currency: $currency
) {
valueInCents
}
totalAmountReceivedTimeSeries(
net: true
dateFrom: $yearAgo
dateFrom: $yearFrom
dateTo: $yearTo
timeUnit: MONTH
includeChildren: true
currency: $currency
Expand All @@ -67,13 +76,20 @@ export const accountsQuery = gql`
}
PAST_QUARTER: stats {
contributorsCount(includeChildren: true, dateFrom: $quarterAgo)
totalAmountSpent(net: true, includeChildren: true, dateFrom: $quarterAgo, currency: $currency) {
contributorsCount(includeChildren: true, dateFrom: $quarterFrom, dateTo: $quarterTo)
totalAmountSpent(
net: true
includeChildren: true
dateFrom: $quarterFrom
dateTo: $quarterTo
currency: $currency
) {
valueInCents
}
totalAmountReceivedTimeSeries(
net: true
dateFrom: $quarterAgo
dateFrom: $quarterFrom
dateTo: $quarterTo
timeUnit: WEEK
includeChildren: true
currency: $currency
Expand Down
12 changes: 8 additions & 4 deletions scripts/fetch-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ async function graphqlRequest(query, variables: any = {}) {

async function fetchDataForPage(host) {
const { slug, currency, root } = host;
const quarterAgo = dayjs.utc().subtract(12, 'week').startOf('isoWeek').toISOString();
const yearAgo = dayjs.utc().subtract(12, 'month').startOf('month').toISOString();
const quarterFrom = dayjs.utc().subtract(12, 'week').startOf('isoWeek').toISOString();
const quarterTo = dayjs.utc().subtract(1, 'week').endOf('isoWeek').toISOString();
const yearFrom = dayjs.utc().subtract(12, 'month').startOf('month').toISOString();
const yearTo = dayjs.utc().subtract(1, 'month').endOf('month').toISOString();

const variables = {
...(root ? { host: host.hostSlugs.map(slug => ({ slug })) } : { host: { slug } }),
currency,
quarterAgo,
yearAgo,
quarterFrom,
quarterTo,
yearFrom,
yearTo,
offset: 0,
limit: 250,
};
Expand Down

1 comment on commit dc4871a

@vercel
Copy link

@vercel vercel bot commented on dc4871a Jan 11, 2023

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.