(
telemetryId: string,
filters: BaseQueryFilters = {},
options: QueryOptions = {}
)
| 101 | } |
| 102 | |
| 103 | export async function parseTelemetryFilters( |
| 104 | telemetryId: string, |
| 105 | filters: BaseQueryFilters = {}, |
| 106 | options: QueryOptions = {} |
| 107 | ) { |
| 108 | const telemetry = await loadTelemetry(telemetryId); |
| 109 | |
| 110 | if (!telemetry) { |
| 111 | throw new Error('Not found telemetry'); |
| 112 | } |
| 113 | |
| 114 | return { |
| 115 | joinSession: |
| 116 | options?.joinSession || |
| 117 | Object.entries(filters).find( |
| 118 | ([key, value]) => |
| 119 | typeof value !== 'undefined' && SESSION_COLUMNS.includes(key) |
| 120 | ) |
| 121 | ? Prisma.sql([ |
| 122 | `inner join "TelemetrySession" on "TelemetryEvent"."sessionId" = "TelemetrySession"."id"`, |
| 123 | ]) |
| 124 | : Prisma.empty, |
| 125 | filterQuery: getTelemetryFilterQuery(filters, options), |
| 126 | params: { |
| 127 | ...normalizeFilters(filters), |
| 128 | telemetryId, |
| 129 | startDate: dayjs(filters.startDate).toISOString(), |
| 130 | endDate: filters.endDate |
| 131 | ? dayjs(filters.endDate).toISOString() |
| 132 | : undefined, |
| 133 | }, |
| 134 | }; |
| 135 | } |
| 136 | |
| 137 | function normalizeFilters(filters: Record<string, any> = {}) { |
| 138 | return Object.keys(filters).reduce( |
no test coverage detected