diff --git a/src/registry/common/register.ts b/src/registry/common/register.ts index 0be2632..f8af399 100644 --- a/src/registry/common/register.ts +++ b/src/registry/common/register.ts @@ -10,6 +10,8 @@ import {Workbook} from './entities/workbook/workbook'; import {colorPalettesAdminValidator} from './utils/color-palettes/utils'; import {checkEmbedding} from './utils/embedding/utils'; import { + checkCreateEntryAvailability, + checkUpdateEntryAvailability, getEntryAddFormattedFieldsHook, getEntryBeforeDbRequestHook, isNeedBypassEntryByKey, @@ -33,5 +35,7 @@ export const registerCommonPlugins = () => { getEntryBeforeDbRequestHook, getEntryAddFormattedFieldsHook, checkEmbedding, + checkCreateEntryAvailability, + checkUpdateEntryAvailability, }); }; diff --git a/src/registry/common/utils/entry/types.ts b/src/registry/common/utils/entry/types.ts index 3aca7ee..9fa6705 100644 --- a/src/registry/common/utils/entry/types.ts +++ b/src/registry/common/utils/entry/types.ts @@ -17,12 +17,14 @@ export type GetEntryAddFormattedFieldsHook = (args: { export type CheckCreateEntryAvailability = (args: { ctx: AppContext; + tenantId: string; scope: EntryScope; type: string | undefined; }) => Promise; export type CheckUpdateEntryAvailability = (args: { ctx: AppContext; + tenantId: string; scope: EntryScope; type: string | undefined; }) => Promise; diff --git a/src/registry/common/utils/entry/utils.ts b/src/registry/common/utils/entry/utils.ts index 7ad397f..0697acd 100644 --- a/src/registry/common/utils/entry/utils.ts +++ b/src/registry/common/utils/entry/utils.ts @@ -1,4 +1,6 @@ import type { + CheckCreateEntryAvailability, + CheckUpdateEntryAvailability, GetEntryAddFormattedFieldsHook, GetEntryBeforeDbRequestHook, IsNeedBypassEntryByKey, @@ -10,3 +12,7 @@ export const getEntryBeforeDbRequestHook: GetEntryBeforeDbRequestHook = () => Pr export const getEntryAddFormattedFieldsHook: GetEntryAddFormattedFieldsHook = () => Promise.resolve({}); + +export const checkCreateEntryAvailability: CheckCreateEntryAvailability = () => Promise.resolve(); + +export const checkUpdateEntryAvailability: CheckUpdateEntryAvailability = () => Promise.resolve(); diff --git a/src/services/entry.service.ts b/src/services/entry.service.ts index 52b1b82..506c4cd 100644 --- a/src/services/entry.service.ts +++ b/src/services/entry.service.ts @@ -41,10 +41,12 @@ export default class EntryService { initialParentId, ctx, }: ST.CreateEntry) { + const {requestId, tenantId, user, dlContext, isPrivateRoute} = ctx.get('info'); + const registry = ctx.get('registry'); const {checkCreateEntryAvailability} = registry.common.functions.get(); - await checkCreateEntryAvailability({ctx, scope, type}); + await checkCreateEntryAvailability({ctx, tenantId, scope, type}); if (workbookId) { return await createEntryInWorkbook(ctx, { @@ -63,8 +65,6 @@ export default class EntryService { }); } - const {requestId, tenantId, user, dlContext, isPrivateRoute} = ctx.get('info'); - return await Entry.create( { requestId, @@ -111,10 +111,17 @@ export default class EntryService { initialParentId, ctx, }: ST.CreateEntry) { + const { + requestId, + tenantId, + dlContext, + // TODO: Send isPrivateRoute. The issue is that the backend takes dl_config from the public and private APIs. + } = ctx.get('info'); + const registry = ctx.get('registry'); const {checkCreateEntryAvailability} = registry.common.functions.get(); - await checkCreateEntryAvailability({ctx, scope, type}); + await checkCreateEntryAvailability({ctx, tenantId, scope, type}); if (workbookId) { return await createEntryInWorkbook(ctx, { @@ -133,12 +140,6 @@ export default class EntryService { }); } - const { - requestId, - tenantId, - dlContext, - // TODO: Send isPrivateRoute. The issue is that the backend takes dl_config from the public and private APIs. - } = ctx.get('info'); const requestedBy = { userId: SYSTEM_USER.ID, login: SYSTEM_USER.LOGIN, diff --git a/src/services/entry/actions/update-entry.ts b/src/services/entry/actions/update-entry.ts index ce3546a..f79ec87 100644 --- a/src/services/entry/actions/update-entry.ts +++ b/src/services/entry/actions/update-entry.ts @@ -158,7 +158,12 @@ export async function updateEntry(ctx: CTX, updateData: UpdateEntryData) { await Promise.all([ checkEntryPromise, Lock.checkLock({entryId, lockToken}, ctx), - checkUpdateEntryAvailability({ctx, scope: entry.scope, type: entry.type}), + checkUpdateEntryAvailability({ + ctx, + tenantId: entry.tenantId, + scope: entry.scope, + type: entry.type, + }), ]); } else { throw new AppError(US_ERRORS.NOT_EXIST_ENTRY, {