Removing auto columns from export - the new table will provide these if required.
This commit is contained in:
parent
782faca131
commit
6b13d2ceaa
|
@ -77,6 +77,7 @@ exports.exportView = async ctx => {
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetchView(ctx)
|
await fetchView(ctx)
|
||||||
|
let rows = ctx.body
|
||||||
|
|
||||||
let schema = view && view.meta && view.meta.schema
|
let schema = view && view.meta && view.meta.schema
|
||||||
if (!schema) {
|
if (!schema) {
|
||||||
|
@ -85,11 +86,23 @@ exports.exportView = async ctx => {
|
||||||
schema = table.schema
|
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
|
// make sure no "undefined" entries appear in the CSV
|
||||||
if (format === exporters.ExportFormats.CSV) {
|
if (format === exporters.ExportFormats.CSV) {
|
||||||
const schemaKeys = Object.keys(schema)
|
const schemaKeys = Object.keys(schema)
|
||||||
for (let key of schemaKeys) {
|
for (let key of schemaKeys) {
|
||||||
for (let row of ctx.body) {
|
for (let row of rows) {
|
||||||
if (row[key] == null) {
|
if (row[key] == null) {
|
||||||
row[key] = ""
|
row[key] = ""
|
||||||
}
|
}
|
||||||
|
@ -103,5 +116,5 @@ exports.exportView = async ctx => {
|
||||||
const filename = `${viewName}.${format}`
|
const filename = `${viewName}.${format}`
|
||||||
// send down the file
|
// send down the file
|
||||||
ctx.attachment(filename)
|
ctx.attachment(filename)
|
||||||
ctx.body = apiFileReturn(exporter(headers, ctx.body))
|
ctx.body = apiFileReturn(exporter(headers, rows))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue