Created VisitsExporter test

This commit is contained in:
Alejandro Celaya
2021-03-14 13:16:20 +01:00
parent 03f63e3ee3
commit 482489599e
3 changed files with 70 additions and 15 deletions

View File

@@ -1,5 +1,4 @@
import { CsvJson } from 'csvjson';
import { head, keys } from 'ramda';
import { NormalizedVisit } from '../types';
import { saveCsv } from '../../utils/helpers/csv';
@@ -10,15 +9,15 @@ export class VisitsExporter {
) {}
public readonly exportVisits = (filename: string, visits: NormalizedVisit[]) => {
try {
const csv = this.csvjson.toCSV(visits, {
headers: keys(head(visits)).join(','),
});
saveCsv(this.window, csv, filename);
} catch (e) {
// FIXME Handle error
console.error(e);
if (!visits.length) {
return;
}
const [ firstVisit ] = visits;
const csv = this.csvjson.toCSV(visits, {
headers: Object.keys(firstVisit).join(','),
});
saveCsv(this.window, csv, filename);
};
}