diff --git a/packages/nocodb/src/models/BaseUser.ts b/packages/nocodb/src/models/BaseUser.ts index 2db59f94ec..e1392b8947 100644 --- a/packages/nocodb/src/models/BaseUser.ts +++ b/packages/nocodb/src/models/BaseUser.ts @@ -178,6 +178,31 @@ export default class BaseUser { return this.castType(baseUser); } + /** + * Check if user entry exists in BaseUser table + * @param context + * @param baseId + * @param userId + * @param ncMeta + */ + public static async exists( + context: NcContext, + baseId: string, + userId: string, + ncMeta = Noco.ncMeta, + ): Promise { + const baseUser = await ncMeta.metaGet2( + context.workspace_id, + context.base_id, + MetaTable.PROJECT_USERS, + { + base_id: baseId, + fk_user_id: userId, + }, + ) + return !!baseUser; + } + public static async getUsersList( context: NcContext, { diff --git a/packages/nocodb/src/services/base-users/base-users.service.ts b/packages/nocodb/src/services/base-users/base-users.service.ts index 35e7c8bece..a2d5918f0b 100644 --- a/packages/nocodb/src/services/base-users/base-users.service.ts +++ b/packages/nocodb/src/services/base-users/base-users.service.ts @@ -461,7 +461,7 @@ export class BaseUsersService { if (Object.keys(baseUserData).length) { // create new base user if it doesn't exist - if (!(await BaseUser.get(context, param.baseId, param.user?.id))) { + if (!(await BaseUser.exists(context, param.baseId, param.user?.id))) { await BaseUser.insert(context, { ...baseUserData, base_id: param.baseId,