fix: get async json schema (#3705)

* fix: get async json schema

* fix: test
This commit is contained in:
ChengLei Shao 2024-03-13 16:17:18 +08:00 committed by GitHub
parent 0123a3320b
commit f6590d1331
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { Collection, Database } from '@nocobase/database';
import { MockServer, createMockServer } from '@nocobase/test';
import { createMockServer, MockServer } from '@nocobase/test';
import { SchemaNode } from '../dao/ui_schema_node_dao';
import UiSchemaRepository from '../repository';
@ -387,6 +387,28 @@ describe('ui_schema repository', () => {
expect(schema).toBeDefined();
});
it('should get root async json schema', async () => {
await repository.insert({
'x-uid': 'n1',
async: true,
name: 'a',
type: 'object',
properties: {
b: {
'x-uid': 'n2',
type: 'object',
properties: {
c: { 'x-uid': 'n3' },
},
},
d: { 'x-uid': 'n4' },
},
});
const schema = await repository.getJsonSchema('n1');
expect(schema).toBeDefined();
});
it('should getProperties', async () => {
await repository.insert(schema);
const rootNode = await repository.findOne({

View File

@ -1013,7 +1013,7 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
LEFT JOIN ${this.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
LEFT JOIN ${this.uiSchemaTreePathTableName} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
LEFT JOIN ${this.uiSchemaTreePathTableName} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
WHERE TreePath.ancestor = :ancestor AND (NodeInfo.async = false or TreePath.depth = 1)`;
WHERE TreePath.ancestor = :ancestor AND (NodeInfo.async = false or TreePath.depth <= 1)`;
const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {
replacements: {
@ -1043,7 +1043,9 @@ WHERE TreeTable.depth = 1 AND TreeTable.ancestor = :ancestor and TreeTable.sort
LEFT JOIN ${this.uiSchemasTableName} as "SchemaTable" ON "SchemaTable"."x-uid" = TreePath.descendant
LEFT JOIN ${treeTable} as NodeInfo ON NodeInfo.descendant = "SchemaTable"."x-uid" and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
LEFT JOIN ${treeTable} as ParentPath ON (ParentPath.descendant = "SchemaTable"."x-uid" AND ParentPath.depth = 1)
WHERE TreePath.ancestor = :ancestor ${options?.includeAsyncNode ? '' : 'AND (NodeInfo.async != true )'}
WHERE TreePath.ancestor = :ancestor ${
options?.includeAsyncNode ? '' : 'AND (NodeInfo.async != true or TreePath.depth = 0)'
}
`;
const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {