Skip to content

Commit

Permalink
Export raw of table with deepness 0 only if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Léo Frachet committed Mar 15, 2018
1 parent a9c8edf commit 9dc5d27
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions helpers/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ function exportTable(tableName, gtfs, outputPath, callback) {

if (deepness === 0) {
let item = gtfs.getIndexedTable(tableName);
if (gtfs._preExportItemFunction) {
item = gtfs._preExportItemFunction(item);
if (item) {
if (gtfs._preExportItemFunction) {
item = gtfs._preExportItemFunction(item, tableName);
}
const row = fromObjectToCsvString(item, keys);
fs.appendFile(outputFullPath, row, callback);
}
const row = fromObjectToCsvString(item, keys);
fs.appendFile(outputFullPath, row, callback);
return;
}

Expand All @@ -96,13 +98,13 @@ function exportTable(tableName, gtfs, outputPath, callback) {
async.eachSeries(gtfs.getIndexedTable(tableName), acomb.ensureAsync(([key, object], subDone) => {
if (deepness === 1) {
if (gtfs._preExportItemFunction) {
object = gtfs._preExportItemFunction(object);
object = gtfs._preExportItemFunction(object, tableName, key);
}
rowsBuffer.push(fromObjectToCsvString(object, keys));
} else if (deepness === 2) {
object.forEach((subObject) => {
object.forEach((subObject, subKey) => {
if (gtfs._preExportItemFunction) {
subObject = gtfs._preExportItemFunction(subObject);
subObject = gtfs._preExportItemFunction(subObject, tableName, key, subKey);
}
rowsBuffer.push(fromObjectToCsvString(subObject, keys));
});
Expand Down

0 comments on commit 9dc5d27

Please sign in to comment.