fix(import): filter non-existent fields
This commit is contained in:
parent
c3a1538435
commit
2008bfa54a
@ -5,6 +5,7 @@ import { EventEmitter } from 'events';
|
||||
import { backOff } from 'exponential-backoff';
|
||||
import glob from 'glob';
|
||||
import lodash from 'lodash';
|
||||
import { nanoid } from 'nanoid';
|
||||
import { basename, isAbsolute, resolve } from 'path';
|
||||
import semver from 'semver';
|
||||
import {
|
||||
@ -40,6 +41,7 @@ import QueryInterface from './query-interface/query-interface';
|
||||
import buildQueryInterface from './query-interface/query-interface-builder';
|
||||
import { RelationRepository } from './relation-repository/relation-repository';
|
||||
import { Repository } from './repository';
|
||||
import { SqlCollection } from './sql-collection/sql-collection';
|
||||
import {
|
||||
AfterDefineCollectionListener,
|
||||
BeforeDefineCollectionListener,
|
||||
@ -70,8 +72,6 @@ import {
|
||||
import { patchSequelizeQueryInterface, snakeCase } from './utils';
|
||||
import { BaseValueParser, registerFieldValueParsers } from './value-parsers';
|
||||
import { ViewCollection } from './view-collection';
|
||||
import { SqlCollection } from './sql-collection/sql-collection';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
export type MergeOptions = merge.Options;
|
||||
|
||||
@ -614,7 +614,8 @@ export class Database extends EventEmitter implements AsyncEmitter {
|
||||
}
|
||||
|
||||
buildFieldValueParser<T extends BaseValueParser>(field: Field, ctx: any) {
|
||||
const Parser = this.fieldValueParsers.has(field.type)
|
||||
const Parser =
|
||||
field && this.fieldValueParsers.has(field.type)
|
||||
? this.fieldValueParsers.get(field.type)
|
||||
: this.fieldValueParsers.get('default');
|
||||
const parser = new Parser(field, ctx);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { Context, Next } from '@nocobase/actions';
|
||||
import { Collection, Repository } from '@nocobase/database';
|
||||
import { uid } from '@nocobase/utils';
|
||||
import xlsx from 'node-xlsx';
|
||||
import XLSX from 'xlsx';
|
||||
import { namespace } from '../../';
|
||||
@ -39,12 +40,14 @@ class Importer {
|
||||
if (typeof columns === 'string') {
|
||||
columns = JSON.parse(columns);
|
||||
}
|
||||
this.columns = columns.map((column) => {
|
||||
this.columns = columns
|
||||
.map((column) => {
|
||||
return {
|
||||
...column,
|
||||
field: this.collection.fields.get(column.dataIndex[0]),
|
||||
};
|
||||
});
|
||||
})
|
||||
.filter((col) => col.field);
|
||||
const str = this.columns.map((column) => column.defaultTitle).join('||');
|
||||
for (const row of rows) {
|
||||
if (this.hasHeaderRow()) {
|
||||
@ -152,7 +155,7 @@ export async function importXlsx(ctx: Context, next: Next) {
|
||||
ctx.body = {
|
||||
rows: xlsx.build([
|
||||
{
|
||||
name: ctx.file.originalname,
|
||||
name: `${uid()}.xlsx`,
|
||||
data: [importer.headerRow].concat(failure),
|
||||
},
|
||||
]),
|
||||
|
Loading…
Reference in New Issue
Block a user