feat: add report generation runs
This commit is contained in:
@@ -486,7 +486,7 @@ export type Report = {
|
||||
};
|
||||
|
||||
export type CreateReport = {
|
||||
report_type: "monthly" | "area_special" | "neighborhood_memo";
|
||||
report_type: "monthly" | "weekly" | "area_special" | "neighborhood_memo";
|
||||
title: string;
|
||||
target_month?: string;
|
||||
area_id?: string;
|
||||
@@ -505,6 +505,44 @@ export type ReportFilters = {
|
||||
status?: string;
|
||||
};
|
||||
|
||||
export type ReportTemplate = {
|
||||
template_id: number;
|
||||
template_key: string;
|
||||
name: string;
|
||||
report_type: string;
|
||||
cadence: string;
|
||||
description: string;
|
||||
body_template: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
};
|
||||
|
||||
export type ReportGenerationRun = {
|
||||
generation_run_id: number;
|
||||
template_id: number;
|
||||
template_key: string;
|
||||
template_name: string;
|
||||
target_month: string;
|
||||
status: string;
|
||||
report_id: number | null;
|
||||
report_title: string | null;
|
||||
parameters: Record<string, unknown>;
|
||||
error_message: string | null;
|
||||
started_at: string;
|
||||
finished_at: string | null;
|
||||
};
|
||||
|
||||
export type CreateReportGenerationRun = {
|
||||
template_key: string;
|
||||
target_month: string;
|
||||
parameters?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export type ReportGenerationRunResponse = {
|
||||
generation_run: ReportGenerationRun;
|
||||
report: Report | null;
|
||||
};
|
||||
|
||||
export type ComparisonMetricValue = {
|
||||
id: string;
|
||||
value: number | null;
|
||||
@@ -798,6 +836,34 @@ export async function createReport(payload: CreateReport): Promise<Report> {
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchReportTemplates(): Promise<ReportTemplate[]> {
|
||||
return fetchJson("/api/v1/report-templates");
|
||||
}
|
||||
|
||||
export async function fetchReportGenerationRuns(filters: {
|
||||
target_month?: string;
|
||||
template_key?: string;
|
||||
status?: string;
|
||||
} = {}): Promise<ReportGenerationRun[]> {
|
||||
const params = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(filters)) {
|
||||
if (value) {
|
||||
params.set(key, value);
|
||||
}
|
||||
}
|
||||
const query = params.toString();
|
||||
return fetchJson(`/api/v1/report-generation-runs${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
export async function createReportGenerationRun(
|
||||
payload: CreateReportGenerationRun,
|
||||
): Promise<ReportGenerationRunResponse> {
|
||||
return fetchJson("/api/v1/report-generation-runs", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchJson<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(`${API_BASE_URL}${path}`, {
|
||||
...init,
|
||||
|
||||
Reference in New Issue
Block a user