MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / getReportDataCore

Function getReportDataCore

packages/db/src/services/reports.service.ts:180–221  ·  view source on GitHub ↗
(input: {
  projectId: string;
  reportId: string;
  organizationId: string;
})

Source from the content-addressed store, hash-verified

178}
179
180export 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}

Callers 1

getReportDataFunction · 0.90

Calls 5

getSettingsForProjectFunction · 0.90
getChartStartEndDateFunction · 0.90
transformReportFunction · 0.85
getFunnelMethod · 0.80
executeMethod · 0.80

Tested by

no test coverage detected