From 0667efefb46bee394097edafe9a39a919faf94dd Mon Sep 17 00:00:00 2001 From: Chareice Date: Thu, 10 Feb 2022 20:39:05 +0800 Subject: [PATCH] feat: removeSchema Hook with params --- .../src/server-hooks/hooks/removeSchema.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/plugin-ui-schema-storage/src/server-hooks/hooks/removeSchema.ts diff --git a/packages/plugin-ui-schema-storage/src/server-hooks/hooks/removeSchema.ts b/packages/plugin-ui-schema-storage/src/server-hooks/hooks/removeSchema.ts new file mode 100644 index 0000000000..4a43219842 --- /dev/null +++ b/packages/plugin-ui-schema-storage/src/server-hooks/hooks/removeSchema.ts @@ -0,0 +1,18 @@ +import { hookFactory } from './factory'; +import { UiSchemaRepository } from '@nocobase/plugin-ui-schema-storage'; + +export async function removeSchema({ schemaInstance, options, db, params }) { + const { transaction } = options; + const uiSchemaRepository: UiSchemaRepository = db.getRepository('ui_schemas'); + const uid = schemaInstance.get('uid') as string; + + if (params?.removeEmptyParents) { + await uiSchemaRepository.removeEmptyParents({ + uid, + breakComponent: params['breakComponent'], + transaction, + }); + } else { + await uiSchemaRepository.remove(uid); + } +}