(input: {
projectId: string;
reportId: string;
organizationId: string;
})
| 178 | } |
| 179 | |
| 180 | export async function getReportDataCore(input: { |
| 181 | projectId: string; |
| 182 | reportId: string; |
| 183 | organizationId: string; |
| 184 | }) { |
| 185 | const rawReport = await db.report.findUnique({ |
| 186 | where: { id: input.reportId, projectId: input.projectId }, |
| 187 | include: { layout: true }, |
| 188 | }); |
| 189 | |
| 190 | if (!rawReport) { |
| 191 | throw new Error(`Report not found: ${input.reportId}`); |
| 192 | } |
| 193 | |
| 194 | const report = transformReport(rawReport); |
| 195 | const { timezone } = await getSettingsForProject(input.projectId); |
| 196 | const { startDate, endDate } = getChartStartEndDate(report, timezone); |
| 197 | const chartInput = { ...report, startDate, endDate, timezone }; |
| 198 | |
| 199 | const meta = { |
| 200 | id: report.id, |
| 201 | name: report.name, |
| 202 | chartType: report.chartType, |
| 203 | range: report.range, |
| 204 | interval: report.interval, |
| 205 | startDate, |
| 206 | endDate, |
| 207 | }; |
| 208 | |
| 209 | if (report.chartType === 'funnel') { |
| 210 | const result = await funnelService.getFunnel(chartInput); |
| 211 | return { ...meta, data: result }; |
| 212 | } |
| 213 | |
| 214 | if (report.chartType === 'metric') { |
| 215 | const result = await AggregateChartEngine.execute(chartInput); |
| 216 | return { ...meta, data: result }; |
| 217 | } |
| 218 | |
| 219 | const result = await ChartEngine.execute(chartInput); |
| 220 | return { ...meta, data: result }; |
| 221 | } |
no test coverage detected