81 lines
2.6 KiB
JavaScript
81 lines
2.6 KiB
JavaScript
import { downloadFile, request } from '../lib/apiClient'
|
|
|
|
/* ============================================================
|
|
reports.js — the saved report library, backend/reports/app.py.
|
|
|
|
A saved report is a parameterisation of a governed analytics query
|
|
(report_type + filters), never free-form SQL. Runs return one tabular
|
|
envelope — {columns:[{key,label}], rows:[{...}]} — so a single DataTable
|
|
renders every type, and /reports/export streams the same table as CSV.
|
|
|
|
Filters prefer `window_days` (rolling) over fixed from/to dates: a saved
|
|
"last 90 days" report should mean the last 90 days on every run.
|
|
Permissions: reports.view to list/run, reports.create / .edit / .delete
|
|
to manage, reports.export to download CSV.
|
|
============================================================ */
|
|
|
|
export const REPORT_TYPES = [
|
|
{ key: 'kpis', label: 'KPI Summary' },
|
|
{ key: 'funnel', label: 'Hiring Funnel' },
|
|
{ key: 'hiring_trend', label: 'Hiring Trend' },
|
|
{ key: 'source_performance', label: 'Source Performance' },
|
|
{ key: 'recruiter_performance', label: 'Recruiter Performance' },
|
|
{ key: 'department_performance', label: 'Department Performance' },
|
|
]
|
|
|
|
export function list() {
|
|
return request('/reports/fetch')
|
|
}
|
|
|
|
export function create({ name, reportType, description, filters } = {}) {
|
|
return request('/reports/create', {
|
|
method: 'POST',
|
|
body: { name, report_type: reportType, description, filters },
|
|
})
|
|
}
|
|
|
|
export function update(recordId, body) {
|
|
return request('/reports/update', {
|
|
method: 'PATCH',
|
|
params: { record_id: recordId },
|
|
body,
|
|
})
|
|
}
|
|
|
|
export function remove(recordId) {
|
|
return request('/reports/delete', {
|
|
method: 'DELETE',
|
|
params: { record_id: recordId },
|
|
})
|
|
}
|
|
|
|
/** Run a saved report (recordId) or an ad-hoc definition (reportType + filters). */
|
|
export function run({ recordId, reportType, filters } = {}) {
|
|
return request('/reports/run', {
|
|
method: 'POST',
|
|
body: { record_id: recordId, report_type: reportType, filters },
|
|
})
|
|
}
|
|
|
|
export function runs(recordId) {
|
|
return request('/reports/runs/fetch', { params: { record_id: recordId } })
|
|
}
|
|
|
|
/** CSV download via Content-Disposition; the browser save is handled by downloadFile. */
|
|
export function exportCsv({ recordId, reportType, filters } = {}) {
|
|
const f = filters || {}
|
|
return downloadFile('/reports/export', {
|
|
params: {
|
|
record_id: recordId,
|
|
report_type: reportType,
|
|
from_date: f.from_date,
|
|
to_date: f.to_date,
|
|
window_days: f.window_days,
|
|
department: f.department,
|
|
recruiter_id: f.recruiter_id,
|
|
months: f.months,
|
|
top: f.top,
|
|
},
|
|
})
|
|
}
|