|
|
|
@ -77,6 +77,7 @@ exports.exportView = async ctx => { |
|
|
|
} |
|
|
|
|
|
|
|
await fetchView(ctx) |
|
|
|
let rows = ctx.body |
|
|
|
|
|
|
|
let schema = view && view.meta && view.meta.schema |
|
|
|
if (!schema) { |
|
|
|
@ -85,11 +86,23 @@ exports.exportView = async ctx => { |
|
|
|
schema = table.schema |
|
|
|
} |
|
|
|
|
|
|
|
// remove any auto columns
|
|
|
|
const autocolumns = Object.entries(schema) |
|
|
|
.filter(entry => entry[1].autocolumn) |
|
|
|
.map(entry => entry[0]) |
|
|
|
rows.forEach(row => { |
|
|
|
autocolumns.forEach(column => delete row[column]) |
|
|
|
}) |
|
|
|
// delete auto columns from schema
|
|
|
|
autocolumns.forEach(column => { |
|
|
|
delete schema[column] |
|
|
|
}) |
|
|
|
|
|
|
|
// make sure no "undefined" entries appear in the CSV
|
|
|
|
if (format === exporters.ExportFormats.CSV) { |
|
|
|
const schemaKeys = Object.keys(schema) |
|
|
|
for (let key of schemaKeys) { |
|
|
|
for (let row of ctx.body) { |
|
|
|
for (let row of rows) { |
|
|
|
if (row[key] == null) { |
|
|
|
row[key] = "" |
|
|
|
} |
|
|
|
@ -103,5 +116,5 @@ exports.exportView = async ctx => { |
|
|
|
const filename = `${viewName}.${format}` |
|
|
|
// send down the file
|
|
|
|
ctx.attachment(filename) |
|
|
|
ctx.body = apiFileReturn(exporter(headers, ctx.body)) |
|
|
|
ctx.body = apiFileReturn(exporter(headers, rows)) |
|
|
|
} |
|
|
|
|