Removing auto columns from export - the new table will provide these if required.

This commit is contained in:
mike12345567 2021-12-02 16:04:44 +00:00
parent 782faca131
commit 6b13d2ceaa
1 changed files with 15 additions and 2 deletions

View File

@ -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))
}