Fix revenue bigInt but and case insensitive currency

This commit is contained in:
Francis Cao 2025-11-09 21:19:38 -08:00
parent b5795a8b3f
commit bf548c5aca

View file

@ -41,6 +41,15 @@ async function relationalQuery(
currency, currency,
}); });
const joinQuery = filterQuery
? `join website_event
on website_event.website_id = revenue.website_id
and website_event.session_id = revenue.session_id
and website_event.event_id = revenue.event_id
and website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}`
: '';
const chart = await rawQuery( const chart = await rawQuery(
` `
select select
@ -48,17 +57,12 @@ async function relationalQuery(
${getDateSQL('revenue.created_at', unit, timezone)} t, ${getDateSQL('revenue.created_at', unit, timezone)} t,
sum(revenue.revenue) y sum(revenue.revenue) y
from revenue from revenue
join website_event ${joinQuery}
on website_event.website_id = revenue.website_id
and website_event.session_id = revenue.session_id
and website_event.event_id = revenue.event_id
and website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
${cohortQuery} ${cohortQuery}
${joinSessionQuery} ${joinSessionQuery}
where revenue.website_id = {{websiteId::uuid}} where revenue.website_id = {{websiteId::uuid}}
and revenue.created_at between {{startDate}} and {{endDate}} and revenue.created_at between {{startDate}} and {{endDate}}
and revenue.currency like {{currency}} and revenue.currency ilike {{currency}}
${filterQuery} ${filterQuery}
group by x, t group by x, t
order by t order by t
@ -72,19 +76,14 @@ async function relationalQuery(
session.country as name, session.country as name,
sum(revenue) value sum(revenue) value
from revenue from revenue
join website_event ${joinQuery}
on website_event.website_id = revenue.website_id
and website_event.session_id = revenue.session_id
and website_event.event_id = revenue.event_id
and website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
join session join session
on session.website_id = revenue.website_id on session.website_id = revenue.website_id
and session.session_id = revenue.session_id and session.session_id = revenue.session_id
${cohortQuery} ${cohortQuery}
where revenue.website_id = {{websiteId::uuid}} where revenue.website_id = {{websiteId::uuid}}
and revenue.created_at between {{startDate}} and {{endDate}} and revenue.created_at between {{startDate}} and {{endDate}}
and revenue.currency = {{currency}} and revenue.currency ilike {{currency}}
${filterQuery} ${filterQuery}
group by session.country group by session.country
`, `,
@ -98,23 +97,18 @@ async function relationalQuery(
count(distinct revenue.event_id) as count, count(distinct revenue.event_id) as count,
count(distinct revenue.session_id) as unique_count count(distinct revenue.session_id) as unique_count
from revenue from revenue
join website_event ${joinQuery}
on website_event.website_id = revenue.website_id
and website_event.session_id = revenue.session_id
and website_event.event_id = revenue.event_id
and website_event.website_id = {{websiteId::uuid}}
and website_event.created_at between {{startDate}} and {{endDate}}
${cohortQuery} ${cohortQuery}
${joinSessionQuery} ${joinSessionQuery}
where revenue.website_id = {{websiteId::uuid}} where revenue.website_id = {{websiteId::uuid}}
and revenue.created_at between {{startDate}} and {{endDate}} and revenue.created_at between {{startDate}} and {{endDate}}
and revenue.currency = {{currency}} and revenue.currency ilike {{currency}}
${filterQuery} ${filterQuery}
`, `,
queryParams, queryParams,
).then(result => result?.[0]); ).then(result => result?.[0]);
total.average = total.count > 0 ? total.sum / total.count : 0; total.average = total.count > 0 ? Number(total.sum) / Number(total.count) : 0;
return { chart, country, total }; return { chart, country, total };
} }