Merge branch 'main' into next

This commit is contained in:
GitHub Actions Bot 2024-08-03 13:55:02 +00:00
commit 3a9b546f4f
2 changed files with 45 additions and 0 deletions

View File

@ -324,6 +324,48 @@ describe('export to xlsx', () => {
await app.destroy(); await app.destroy();
}); });
it('should throw error when export field not exists', async () => {
const Post = app.db.collection({
name: 'posts',
fields: [
{
name: 'title',
type: 'string',
},
],
});
await app.db.sync();
await Post.repository.create({
values: {
title: 'some_title',
json: {
a: {
b: 'c',
},
},
},
});
const exporter = new XlsxExporter({
collectionManager: app.mainDataSource.collectionManager,
collection: Post,
chunkSize: 10,
columns: [{ dataIndex: ['json'], defaultTitle: '' }],
});
let error: any;
try {
await exporter.run({});
} catch (e) {
error = e;
}
expect(error).toBeDefined();
expect(error.message).toContain('not found');
});
it('should export with json field', async () => { it('should export with json field', async () => {
const Post = app.db.collection({ const Post = app.db.collection({
name: 'posts', name: 'posts',

View File

@ -114,6 +114,9 @@ class XlsxExporter {
} }
const field = this.options.collection.getField(col.dataIndex[0]); const field = this.options.collection.getField(col.dataIndex[0]);
if (!field) {
throw new Error(`Field "${col.dataIndex[0]}" not found: , please check the columns configuration.`);
}
if (field.isRelationField()) { if (field.isRelationField()) {
return col.dataIndex[0]; return col.dataIndex[0];