From 3e7ca294990225d818afa5e4c1837cf3be5bfeed Mon Sep 17 00:00:00 2001 From: Aish1990 Date: Fri, 5 Jul 2024 17:20:10 +0530 Subject: [PATCH 1/2] Fixed Add Organization at admin login fixed as it was not updating the admin's api_user_id at this new organization and user --- apps/drec-api/src/pods/admin/admin.controller.ts | 5 ++++- apps/drec-api/src/pods/user/user.service.ts | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/drec-api/src/pods/admin/admin.controller.ts b/apps/drec-api/src/pods/admin/admin.controller.ts index 3f213b030..41363c5ce 100755 --- a/apps/drec-api/src/pods/admin/admin.controller.ts +++ b/apps/drec-api/src/pods/admin/admin.controller.ts @@ -161,7 +161,10 @@ export class AdminController { type: CreateUserORGDTO, description: 'Returns a new created user', }) - public async createUser(@Body() newUser: CreateUserORGDTO): Promise { + public async createUser(@Body() newUser: CreateUserORGDTO, + @UserDecorator() { api_user_id }: LoggedInUser, + ): Promise { + newUser.api_user_id = api_user_id; return await this.userService.adminnewcreate(newUser); } diff --git a/apps/drec-api/src/pods/user/user.service.ts b/apps/drec-api/src/pods/user/user.service.ts index 3b3072b2c..313602ca4 100755 --- a/apps/drec-api/src/pods/user/user.service.ts +++ b/apps/drec-api/src/pods/user/user.service.ts @@ -166,6 +166,10 @@ export class UserService { inviteuser?: boolean, ): Promise { await this.checkForExistingUser(data.email.toLowerCase()); + const admin = + await this.oauthClientCredentialsService.findOneByApiUserId( + data.api_user_id, + ); let org_id; if (!inviteuser) { const orgdata = { @@ -175,7 +179,7 @@ export class UserService { orgEmail: data.email, address: data.orgAddress, }; - + orgdata['api_user_id'] = admin.api_user_id; if (await this.organizationService.isNameAlreadyTaken(orgdata.name)) { throw new ConflictException({ success: false, @@ -212,6 +216,7 @@ export class UserService { role: role, roleId: roleId, organization: org_id ? { id: org_id } : {}, + api_user_id: admin ? admin.api_user_id : null, }); const { password, ...userData } = user; this.logger.debug( From 39127b81aaadba3706f67ece11dbf9fb1a6fa0ec Mon Sep 17 00:00:00 2001 From: Aish1990 Date: Fri, 5 Jul 2024 19:44:31 +0530 Subject: [PATCH 2/2] Prettier lint Fixed --- apps/drec-api/src/pods/admin/admin.controller.ts | 5 +++-- apps/drec-api/src/pods/user/user.service.ts | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/drec-api/src/pods/admin/admin.controller.ts b/apps/drec-api/src/pods/admin/admin.controller.ts index 41363c5ce..abeafa9cd 100755 --- a/apps/drec-api/src/pods/admin/admin.controller.ts +++ b/apps/drec-api/src/pods/admin/admin.controller.ts @@ -161,8 +161,9 @@ export class AdminController { type: CreateUserORGDTO, description: 'Returns a new created user', }) - public async createUser(@Body() newUser: CreateUserORGDTO, - @UserDecorator() { api_user_id }: LoggedInUser, + public async createUser( + @Body() newUser: CreateUserORGDTO, + @UserDecorator() { api_user_id }: LoggedInUser, ): Promise { newUser.api_user_id = api_user_id; return await this.userService.adminnewcreate(newUser); diff --git a/apps/drec-api/src/pods/user/user.service.ts b/apps/drec-api/src/pods/user/user.service.ts index 313602ca4..3a050e4c8 100755 --- a/apps/drec-api/src/pods/user/user.service.ts +++ b/apps/drec-api/src/pods/user/user.service.ts @@ -166,10 +166,9 @@ export class UserService { inviteuser?: boolean, ): Promise { await this.checkForExistingUser(data.email.toLowerCase()); - const admin = - await this.oauthClientCredentialsService.findOneByApiUserId( - data.api_user_id, - ); + const admin = await this.oauthClientCredentialsService.findOneByApiUserId( + data.api_user_id, + ); let org_id; if (!inviteuser) { const orgdata = {