fix: get async json schema (#3705)
* fix: get async json schema * fix: test
This commit is contained in:
parent
0123a3320b
commit
f6590d1331
packages/plugins/@nocobase/plugin-ui-schema-storage/src/server
@ -1,5 +1,5 @@
|
|||||||
import { Collection, Database } from '@nocobase/database';
|
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 { SchemaNode } from '../dao/ui_schema_node_dao';
|
||||||
import UiSchemaRepository from '../repository';
|
import UiSchemaRepository from '../repository';
|
||||||
|
|
||||||
@ -387,6 +387,28 @@ describe('ui_schema repository', () => {
|
|||||||
expect(schema).toBeDefined();
|
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 () => {
|
it('should getProperties', async () => {
|
||||||
await repository.insert(schema);
|
await repository.insert(schema);
|
||||||
const rootNode = await repository.findOne({
|
const rootNode = await repository.findOne({
|
||||||
|
@ -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.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 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)
|
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), {
|
const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {
|
||||||
replacements: {
|
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 ${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 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)
|
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), {
|
const nodes = await db.sequelize.query(this.sqlAdapter(rawSql), {
|
||||||
|
Loading…
Reference in New Issue
Block a user