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 { MagicAttributeModel } from '@nocobase/database';
import { HookType } from './server-hooks';
class UiSchemaModel extends MagicAttributeModel { class UiSchemaModel extends MagicAttributeModel {}
getListenServerHooks(type: HookType) {
const hooks = this.get('x-server-hooks') || [];
return hooks.filter((hook) => {
hook.type = '';
});
}
}
export { UiSchemaModel }; export { UiSchemaModel };

View File

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