-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add dropdown logic for revenue report, defaults to USD for unknown cu…
…rrency code
- Loading branch information
1 parent
214396f
commit be50e8a
Showing
8 changed files
with
155 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,9 @@ | |
gap: 20px; | ||
margin-bottom: 40px; | ||
} | ||
|
||
.row { | ||
display: flex; | ||
align-items: center; | ||
gap: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useApi } from './useApi'; | ||
|
||
export function useRevenueValues(websiteId: string, startDate: Date, endDate: Date) { | ||
const { get, useQuery } = useApi(); | ||
|
||
return useQuery({ | ||
queryKey: ['revenue:values', { websiteId, startDate, endDate }], | ||
queryFn: () => | ||
get(`/reports/revenue`, { | ||
websiteId, | ||
startDate, | ||
endDate, | ||
}), | ||
enabled: !!(websiteId && startDate && endDate), | ||
}); | ||
} | ||
|
||
export default useRevenueValues; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import prisma from 'lib/prisma'; | ||
import clickhouse from 'lib/clickhouse'; | ||
import { runQuery, CLICKHOUSE, PRISMA, getDatabaseType, POSTGRESQL } from 'lib/db'; | ||
|
||
export async function getRevenueValues( | ||
...args: [ | ||
websiteId: string, | ||
criteria: { | ||
startDate: Date; | ||
endDate: Date; | ||
}, | ||
] | ||
) { | ||
return runQuery({ | ||
[PRISMA]: () => relationalQuery(...args), | ||
[CLICKHOUSE]: () => clickhouseQuery(...args), | ||
}); | ||
} | ||
|
||
async function relationalQuery( | ||
websiteId: string, | ||
criteria: { | ||
startDate: Date; | ||
endDate: Date; | ||
}, | ||
) { | ||
const { rawQuery } = prisma; | ||
const { startDate, endDate } = criteria; | ||
|
||
const db = getDatabaseType(); | ||
const like = db === POSTGRESQL ? 'ilike' : 'like'; | ||
|
||
return rawQuery( | ||
` | ||
select distinct string_value as currency | ||
from event_data | ||
where website_id = {websiteId:UUID} | ||
and created_at between {startDate:DateTime64} and {endDate:DateTime64} | ||
and data_key ${like} '%currency%' | ||
order by currency | ||
`, | ||
{ | ||
websiteId, | ||
startDate, | ||
endDate, | ||
}, | ||
); | ||
} | ||
|
||
async function clickhouseQuery( | ||
websiteId: string, | ||
criteria: { | ||
startDate: Date; | ||
endDate: Date; | ||
}, | ||
) { | ||
const { rawQuery } = clickhouse; | ||
const { startDate, endDate } = criteria; | ||
|
||
return rawQuery( | ||
` | ||
select distinct string_value as currency | ||
from event_data | ||
where website_id = {websiteId:UUID} | ||
and created_at between {startDate:DateTime64} and {endDate:DateTime64} | ||
and positionCaseInsensitive(data_key, 'currency') > 0 | ||
order by currency | ||
`, | ||
{ | ||
websiteId, | ||
startDate, | ||
endDate, | ||
}, | ||
); | ||
} |