fix: call root server hook after insertNewSchema (#282)
This commit is contained in:
parent
8b5ddf4501
commit
571b077840
@ -264,6 +264,38 @@ describe('server hooks', () => {
|
|||||||
expect(jsonTree['properties']['child2']).not.toBeDefined();
|
expect(jsonTree['properties']['child2']).not.toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should bind menu to role when insert new menu using insertAdjacent', async () => {
|
||||||
|
await db.getRepository('roles').create({
|
||||||
|
values: {
|
||||||
|
name: 'role1',
|
||||||
|
allowConfigure: true,
|
||||||
|
allowNewMenu: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
'x-uid': 'root',
|
||||||
|
name: 'root',
|
||||||
|
properties: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
await uiSchemaRepository.insert(schema);
|
||||||
|
|
||||||
|
await uiSchemaRepository.insertAdjacent('afterBegin', 'root', {
|
||||||
|
'x-uid': 'child2',
|
||||||
|
name: 'child2',
|
||||||
|
'x-server-hooks': [
|
||||||
|
{
|
||||||
|
type: 'onSelfCreate',
|
||||||
|
method: 'bindMenuToRole',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const role1Menus = await db.getRepository<BelongsToManyRepository>('roles.menuUiSchemas', 'role1').find();
|
||||||
|
expect(role1Menus.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should bind menu to role when create new menu', async () => {
|
it('should bind menu to role when create new menu', async () => {
|
||||||
await db.getRepository('roles').create({
|
await db.getRepository('roles').create({
|
||||||
values: {
|
values: {
|
||||||
|
@ -594,6 +594,7 @@ export class UiSchemaRepository extends Repository {
|
|||||||
options.removeParentsIfNoChildren = false;
|
options.removeParentsIfNoChildren = false;
|
||||||
} else {
|
} else {
|
||||||
const schemaExists = await this.schemaExists(schema, { transaction });
|
const schemaExists = await this.schemaExists(schema, { transaction });
|
||||||
|
|
||||||
if (schemaExists) {
|
if (schemaExists) {
|
||||||
schema = lodash.isString(schema) ? schema : schema['x-uid'];
|
schema = lodash.isString(schema) ? schema : schema['x-uid'];
|
||||||
} else {
|
} else {
|
||||||
@ -711,6 +712,12 @@ export class UiSchemaRepository extends Repository {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const rootNode = nodes[0];
|
||||||
|
if (rootNode['x-server-hooks']) {
|
||||||
|
const rootModel = await this.findOne({ filter: { 'x-uid': rootNode['x-uid'] }, transaction });
|
||||||
|
await this.database.emitAsync(`${this.collection.name}.afterCreateWithAssociations`, rootModel, options);
|
||||||
|
}
|
||||||
|
|
||||||
if (options?.returnNode) {
|
if (options?.returnNode) {
|
||||||
return nodes;
|
return nodes;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user