chore: server hooks

This commit is contained in:
Chareice 2022-02-09 21:11:29 +08:00 committed by chenos
parent 0526e4ff1f
commit 85ab936c4c
2 changed files with 5 additions and 13 deletions

View File

@ -1,13 +1,5 @@
import { MagicAttributeModel } from '@nocobase/database';
import { HookType } from './server-hooks';
class UiSchemaModel extends MagicAttributeModel {
getListenServerHooks(type: HookType) {
const hooks = this.get('x-server-hooks') || [];
return hooks.filter((hook) => {
hook.type = '';
});
}
}
class UiSchemaModel extends MagicAttributeModel {}
export { UiSchemaModel };

View File

@ -2,7 +2,7 @@ import { Database } from '@nocobase/database';
import { ServerHookModel } from './model';
export type HookType =
| 'onSchemaDestroy'
| 'onSelfDestroy'
| 'onCollectionDestroy'
| 'onCollectionFieldDestroy'
| 'onAnyCollectionFieldDestroy'
@ -82,16 +82,16 @@ export class ServerHooks {
);
}
protected async onUiSchemaCreate(uiSchemaModel, options) {
protected async onUiSchemaCreate(schemaInstance, options) {
const { transaction } = options;
await this.findHooksAndCall(
{
type: 'onSelfCreate',
uid: uiSchemaModel.schema['x-uid'],
uid: schemaInstance.schema['x-uid'],
},
{
uiSchemaModel,
schemaInstance,
options,
},
transaction,