From 12c3915a570236a95f92cf9c26f158a55629c1a4 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 15 Sep 2022 09:27:28 +0800 Subject: [PATCH] fix(plugin-export): filter non-existent fields --- packages/plugins/export/src/server/actions/export-xlsx.ts | 4 ++-- packages/plugins/export/src/server/utils/columns2Appends.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugins/export/src/server/actions/export-xlsx.ts b/packages/plugins/export/src/server/actions/export-xlsx.ts index 0e5ac882ec..a78dbfdc0d 100644 --- a/packages/plugins/export/src/server/actions/export-xlsx.ts +++ b/packages/plugins/export/src/server/actions/export-xlsx.ts @@ -10,10 +10,10 @@ export async function exportXlsx(ctx: Context, next: Next) { if (typeof columns === 'string') { columns = JSON.parse(columns); } - const appends = columns2Appends(columns, ctx); - columns = columns?.filter((col) => col?.dataIndex?.length > 0); const repository = ctx.db.getRepository(resourceName, resourceOf) as Repository; const collection = repository.collection; + columns = columns?.filter((col) => collection.hasField(col.dataIndex[0]) && col?.dataIndex?.length > 0); + const appends = columns2Appends(columns, ctx); const data = await repository.find({ filter, fields, diff --git a/packages/plugins/export/src/server/utils/columns2Appends.ts b/packages/plugins/export/src/server/utils/columns2Appends.ts index 7484b8853d..6ad1197765 100644 --- a/packages/plugins/export/src/server/utils/columns2Appends.ts +++ b/packages/plugins/export/src/server/utils/columns2Appends.ts @@ -6,7 +6,7 @@ export function columns2Appends(columns, ctx) { const appendColumns = []; for (let i = 0, iLen = column.dataIndex.length; i < iLen; i++) { let field = collection.getField(column.dataIndex[i]); - if (field.target) { + if (field?.target) { appendColumns.push(column.dataIndex[i]); collection = ctx.db.getCollection(field.target); }