Browse Source

fix: use exists method to check the entry already present or not

pull/9592/head
Pranav C 2 months ago
parent
commit
5cca492014
  1. 25
      packages/nocodb/src/models/BaseUser.ts
  2. 2
      packages/nocodb/src/services/base-users/base-users.service.ts

25
packages/nocodb/src/models/BaseUser.ts

@ -178,6 +178,31 @@ export default class BaseUser {
return this.castType(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<boolean> {
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( public static async getUsersList(
context: NcContext, context: NcContext,
{ {

2
packages/nocodb/src/services/base-users/base-users.service.ts

@ -461,7 +461,7 @@ export class BaseUsersService {
if (Object.keys(baseUserData).length) { if (Object.keys(baseUserData).length) {
// create new base user if it doesn't exist // 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, { await BaseUser.insert(context, {
...baseUserData, ...baseUserData,
base_id: param.baseId, base_id: param.baseId,

Loading…
Cancel
Save