Skip to content

Commit

Permalink
Handle case with empty tables
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoFrachet committed Dec 29, 2017
1 parent 2ad008f commit 7ab29cf
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions helpers/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ const schema = require('./schema');
* Private functions
*/

function getSample(iterable) {
return (iterable && iterable.values().next()) ? iterable.values().next().value : undefined;
}

function getHHmmss() {
const date = new Date();
return `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
Expand Down Expand Up @@ -67,19 +71,16 @@ function copyUntouchedTable(inputPath, outputPath, tableName, callback) {
}

function getActualKeysForTable(gtfs, tableName) {
const keys = [...schema.keysByTableName[tableName]];
const deepness = schema.deepnessByTableName[tableName];
let sampleItem;
let sampleItem = gtfs.getIndexedTable(tableName);

if (deepness === 0) {
sampleItem = gtfs.getIndexedTable(tableName);
} else if (deepness === 1) {
sampleItem = gtfs.getIndexedTable(tableName).values().next().value;
if (deepness === 1) {
sampleItem = getSample(sampleItem);
} else if (deepness === 2) {
sampleItem = gtfs.getIndexedTable(tableName).values().next().value.values().next().value;
sampleItem = getSample(getSample(sampleItem));
}

const keys = [...schema.keysByTableName[tableName]];

if (sampleItem) {
Object.keys(sampleItem).forEach((key) => {
if (schema.keysByTableName[tableName].includes(key) === false) {
Expand Down

0 comments on commit 7ab29cf

Please sign in to comment.