api: add first version of export api
This commit is contained in:
committed by
Carl-Gerhard Lindesvärd
parent
7ea95afe16
commit
7f8d857508
@@ -248,6 +248,10 @@ export interface GetEventListOptions {
|
||||
cursor?: number;
|
||||
events?: string[] | null;
|
||||
filters?: IChartEventFilter[];
|
||||
startDate?: Date;
|
||||
endDate?: Date;
|
||||
meta?: boolean;
|
||||
profile?: boolean;
|
||||
}
|
||||
|
||||
export async function getEventList({
|
||||
@@ -257,6 +261,10 @@ export async function getEventList({
|
||||
profileId,
|
||||
events,
|
||||
filters,
|
||||
startDate,
|
||||
endDate,
|
||||
meta = true,
|
||||
profile = true,
|
||||
}: GetEventListOptions) {
|
||||
const { sb, getSql, join } = createSqlBuilder();
|
||||
|
||||
@@ -268,6 +276,10 @@ export async function getEventList({
|
||||
sb.where.deviceId = `device_id IN (SELECT device_id as did FROM events WHERE profile_id = ${escape(profileId)} group by did)`;
|
||||
}
|
||||
|
||||
if (startDate && endDate) {
|
||||
sb.where.created_at = `created_at BETWEEN '${formatClickhouseDate(startDate)}' AND '${formatClickhouseDate(endDate)}'`;
|
||||
}
|
||||
|
||||
if (events && events.length > 0) {
|
||||
sb.where.events = `name IN (${join(
|
||||
events.map((event) => escape(event)),
|
||||
@@ -288,7 +300,7 @@ export async function getEventList({
|
||||
|
||||
sb.orderBy.created_at = 'created_at DESC';
|
||||
|
||||
return getEvents(getSql(), { profile: true, meta: true });
|
||||
return getEvents(getSql(), { profile, meta });
|
||||
}
|
||||
|
||||
export async function getEventsCount({
|
||||
@@ -296,6 +308,8 @@ export async function getEventsCount({
|
||||
profileId,
|
||||
events,
|
||||
filters,
|
||||
startDate,
|
||||
endDate,
|
||||
}: Omit<GetEventListOptions, 'cursor' | 'take'>) {
|
||||
const { sb, getSql, join } = createSqlBuilder();
|
||||
sb.where.projectId = `project_id = ${escape(projectId)}`;
|
||||
@@ -303,6 +317,10 @@ export async function getEventsCount({
|
||||
sb.where.profileId = `profile_id = ${escape(profileId)}`;
|
||||
}
|
||||
|
||||
if (startDate && endDate) {
|
||||
sb.where.created_at = `created_at BETWEEN '${formatClickhouseDate(startDate)}' AND '${formatClickhouseDate(endDate)}'`;
|
||||
}
|
||||
|
||||
if (events && events.length > 0) {
|
||||
sb.where.events = `name IN (${join(
|
||||
events.map((event) => escape(event)),
|
||||
|
||||
Reference in New Issue
Block a user