1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00

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 efd95a26f3
commit baf61e37e4

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