-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv-to-report.js
More file actions
40 lines (33 loc) · 1.08 KB
/
csv-to-report.js
File metadata and controls
40 lines (33 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Generate a report from CSV data using ReportForge API
// Usage: node csv-to-report.js
const csvData = `item,amount,quantity,category
Laptop,1299.99,5,Electronics
Keyboard,79.99,20,Peripherals
Monitor,549.99,8,Electronics
Mouse,39.99,25,Peripherals
Headset,149.99,12,Audio
Webcam,89.99,15,Peripherals
Docking Station,249.99,6,Electronics`;
async function generateReport() {
const res = await fetch('https://reportforge-api.vercel.app/api/csv-to-report', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
csv: csvData,
template: 'inventory-status',
title: 'Office Equipment Inventory'
})
});
if (!res.ok) {
console.error(`Error: ${res.status}`);
process.exit(1);
}
const { html, meta } = await res.json();
console.log(`Template: ${meta.template}`);
console.log(`Rows: ${meta.rowCount}`);
console.log(`Columns: ${meta.columns.join(', ')}`);
const fs = await import('fs');
fs.writeFileSync('inventory-report.html', html);
console.log('\nReport saved to inventory-report.html');
}
generateReport();