From 5cca4920147140c539d2a9effbba15129b7d05ce Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sun, 6 Oct 2024 08:03:08 +0000 Subject: [PATCH] fix: use exists method to check the entry already present or not --- packages/nocodb/src/models/BaseUser.ts | 25 +++++++++++++++++++ .../services/base-users/base-users.service.ts | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) 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,