From 729d73b73fdd0c550e2f1ca388a568d04ca96bf2 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Thu, 14 Sep 2023 20:14:22 +0530 Subject: [PATCH 1/5] worked on the username & orgslug feature for public profiles Signed-off-by: @nishad.shirsat --- .../dtos/update-organization-dto.ts | 7 +++- .../organization/organization.controller.ts | 15 +++---- .../src/organization/organization.service.ts | 4 +- .../src/user/dto/update-user-profile.dto.ts | 8 +++- apps/api-gateway/src/user/user.controller.ts | 13 +++--- apps/api-gateway/src/user/user.service.ts | 4 +- .../dtos/create-organization.dto.ts | 1 + .../interfaces/organization.interface.ts | 2 + .../repositories/organization.repository.ts | 14 +++++-- .../src/organization.controller.ts | 2 +- apps/organization/src/organization.service.ts | 42 ++++++++++++++++--- apps/user/interfaces/user.interface.ts | 2 + apps/user/repositories/user.repository.ts | 38 +++++++++++------ apps/user/src/user.controller.ts | 5 +-- apps/user/src/user.service.ts | 34 +++++++++++++-- 15 files changed, 143 insertions(+), 48 deletions(-) diff --git a/apps/api-gateway/src/organization/dtos/update-organization-dto.ts b/apps/api-gateway/src/organization/dtos/update-organization-dto.ts index 44569b38d..1229ddc58 100644 --- a/apps/api-gateway/src/organization/dtos/update-organization-dto.ts +++ b/apps/api-gateway/src/organization/dtos/update-organization-dto.ts @@ -1,5 +1,5 @@ import { ApiExtraModels, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { IsNotEmpty, IsNumber, IsOptional, IsString, MaxLength, MinLength } from 'class-validator'; +import { IsBoolean, IsNotEmpty, IsNumber, IsOptional, IsString, MaxLength, MinLength } from 'class-validator'; import { Transform } from 'class-transformer'; import { trim } from '@credebl/common/cast.helper'; @@ -37,4 +37,9 @@ export class UpdateOrganizationDto { @IsOptional() website: string; + @ApiPropertyOptional({ example: true }) + @IsBoolean({ message: 'isPublic should be boolean' }) + @IsOptional() + isPublic? = false; + } \ No newline at end of file diff --git a/apps/api-gateway/src/organization/organization.controller.ts b/apps/api-gateway/src/organization/organization.controller.ts index 05fafc1da..25934cfe1 100644 --- a/apps/api-gateway/src/organization/organization.controller.ts +++ b/apps/api-gateway/src/organization/organization.controller.ts @@ -1,4 +1,4 @@ -import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiQuery, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; +import { ApiBearerAuth, ApiForbiddenResponse, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags, ApiUnauthorizedResponse } from '@nestjs/swagger'; import { CommonService } from '@credebl/common'; import { Controller, Get, Put, Param, UseGuards, UseFilters } from '@nestjs/common'; import { OrganizationService } from './organization.service'; @@ -109,18 +109,19 @@ export class OrganizationController { return res.status(HttpStatus.OK).json(finalResponse); } - @Get('public-profile') + @Get('public-profiles/:orgSlug') @ApiOperation({ summary: 'Fetch user details', description: 'Fetch user details' }) - @ApiQuery({ - name: 'id', - type: Number, + + @ApiParam({ + name: 'orgSlug', + type: String, required: false }) - async getPublicProfile(@User() reqUser: user, @Query('id') id: number, @Res() res: Response): Promise { - const userData = await this.organizationService.getPublicProfile(id); + async getPublicProfile(@Param('orgSlug') orgSlug: string, @Res() res: Response): Promise { + const userData = await this.organizationService.getPublicProfile(orgSlug); const finalResponse: IResponseType = { statusCode: HttpStatus.OK, diff --git a/apps/api-gateway/src/organization/organization.service.ts b/apps/api-gateway/src/organization/organization.service.ts index eb626e6d1..ba0d6f96d 100644 --- a/apps/api-gateway/src/organization/organization.service.ts +++ b/apps/api-gateway/src/organization/organization.service.ts @@ -65,8 +65,8 @@ export class OrganizationService extends BaseService { return this.sendNats(this.serviceProxy, 'get-public-organizations', payload); } - async getPublicProfile(id: number): Promise<{ response: object }> { - const payload = { id }; + async getPublicProfile(orgSlug: string): Promise<{ response: object }> { + const payload = {orgSlug }; try { return this.sendNats(this.serviceProxy, 'get-organization-public-profile', payload); } catch (error) { diff --git a/apps/api-gateway/src/user/dto/update-user-profile.dto.ts b/apps/api-gateway/src/user/dto/update-user-profile.dto.ts index 88d1c28b5..41484636c 100644 --- a/apps/api-gateway/src/user/dto/update-user-profile.dto.ts +++ b/apps/api-gateway/src/user/dto/update-user-profile.dto.ts @@ -1,6 +1,5 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { IsNotEmpty, IsNumber, IsOptional, IsString} from 'class-validator'; - +import { IsBoolean, IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator'; export class UpdateUserProfileDto { @ApiProperty() @@ -22,4 +21,9 @@ export class UpdateUserProfileDto { @IsString({ message: 'lastName should be string' }) @IsOptional() lastName?: string; + + @ApiPropertyOptional({ example: true }) + @IsBoolean({ message: 'isPublic should be boolean' }) + @IsOptional() + isPublic? = false; } \ No newline at end of file diff --git a/apps/api-gateway/src/user/user.controller.ts b/apps/api-gateway/src/user/user.controller.ts index 0677ad8eb..6c18391e8 100644 --- a/apps/api-gateway/src/user/user.controller.ts +++ b/apps/api-gateway/src/user/user.controller.ts @@ -6,6 +6,7 @@ import { ApiBody, ApiForbiddenResponse, ApiOperation, + ApiParam, ApiQuery, ApiResponse, ApiTags, @@ -222,18 +223,18 @@ export class UserController { } - @Get('public-profile') + @Get('public-profiles/:username') @ApiOperation({ summary: 'Fetch user details', description: 'Fetch user details' }) - @ApiQuery({ - name: 'id', - type: Number, + @ApiParam({ + name: 'username', + type: String, required: false }) - async getPublicProfile(@User() reqUser: user, @Query('id') id: number, @Res() res: Response): Promise { - const userData = await this.userService.getPublicProfile(id); + async getPublicProfile(@Param('username') username: string, @Res() res: Response): Promise { + const userData = await this.userService.getPublicProfile(username); const finalResponse: IResponseType = { statusCode: HttpStatus.OK, diff --git a/apps/api-gateway/src/user/user.service.ts b/apps/api-gateway/src/user/user.service.ts index 6dfa2b0f5..9e97e50ac 100644 --- a/apps/api-gateway/src/user/user.service.ts +++ b/apps/api-gateway/src/user/user.service.ts @@ -53,8 +53,8 @@ export class UserService extends BaseService { } } - async getPublicProfile(id: number): Promise<{ response: object }> { - const payload = { id }; + async getPublicProfile(username: string): Promise<{ response: object }> { + const payload = { username }; try { return this.sendNats(this.serviceProxy, 'get-user-public-profile', payload); } catch (error) { diff --git a/apps/organization/dtos/create-organization.dto.ts b/apps/organization/dtos/create-organization.dto.ts index c2fd5249e..2d54b1ef7 100644 --- a/apps/organization/dtos/create-organization.dto.ts +++ b/apps/organization/dtos/create-organization.dto.ts @@ -6,6 +6,7 @@ export class CreateOrganizationDto { description?: string; logo?: string; website?: string; + orgSlug?:string; } export class CreateUserRoleOrgDto { diff --git a/apps/organization/interfaces/organization.interface.ts b/apps/organization/interfaces/organization.interface.ts index 5a1d9667f..f8cbb9e9c 100644 --- a/apps/organization/interfaces/organization.interface.ts +++ b/apps/organization/interfaces/organization.interface.ts @@ -18,4 +18,6 @@ export interface IUpdateOrganization { orgId: string; logo?: string; website?: string; + orgSlug?: string; + isPublic?:boolean } \ No newline at end of file diff --git a/apps/organization/repositories/organization.repository.ts b/apps/organization/repositories/organization.repository.ts index 1f44ebcf9..8339b220a 100644 --- a/apps/organization/repositories/organization.repository.ts +++ b/apps/organization/repositories/organization.repository.ts @@ -53,7 +53,8 @@ export class OrganizationRepository { name: createOrgDto.name, logoUrl: createOrgDto.logo, description: createOrgDto.description, - website: createOrgDto.website + website: createOrgDto.website, + orgSlug: createOrgDto.orgSlug } }); } catch (error) { @@ -78,10 +79,11 @@ export class OrganizationRepository { name: updateOrgDto.name, logoUrl: updateOrgDto.logo, description: updateOrgDto.description, - website: updateOrgDto.website + website: updateOrgDto.website, + orgSlug: updateOrgDto.orgSlug, + publicProfile: updateOrgDto.isPublic } }); - } catch (error) { this.logger.error(`error: ${JSON.stringify(error)}`); throw new InternalServerErrorException(error); @@ -257,6 +259,12 @@ export class OrganizationRepository { org_agent_type: true, ledgers: true } + }, + userOrgRoles: { + include:{ + user: true, + orgRole:true + } } } }); diff --git a/apps/organization/src/organization.controller.ts b/apps/organization/src/organization.controller.ts index 6302aa0cb..85edbe3c9 100644 --- a/apps/organization/src/organization.controller.ts +++ b/apps/organization/src/organization.controller.ts @@ -72,7 +72,7 @@ export class OrganizationController { } @MessagePattern({ cmd: 'get-organization-public-profile' }) - async getPublicProfile(payload: { id }): Promise { + async getPublicProfile(payload: { orgSlug }): Promise { return this.organizationService.getPublicProfile(payload); } diff --git a/apps/organization/src/organization.service.ts b/apps/organization/src/organization.service.ts index ec5ddfa96..ddafd90d8 100644 --- a/apps/organization/src/organization.service.ts +++ b/apps/organization/src/organization.service.ts @@ -48,6 +48,9 @@ export class OrganizationService { throw new ConflictException(ResponseMessages.organisation.error.exists); } + const orgSlug = await this.createOrgSlug(createOrgDto.name); + createOrgDto.orgSlug = orgSlug; + const organizationDetails = await this.organizationRepository.createOrganization(createOrgDto); const ownerRoleData = await this.orgRoleService.getRole(OrgRoles.OWNER); @@ -61,6 +64,21 @@ export class OrganizationService { } } + + /** + * + * @param orgName + * @returns OrgSlug + */ + createOrgSlug(orgName: string): string { + return orgName + .toLowerCase() // Convert the input to lowercase + .replace(/\s+/g, '-') // Replace spaces with hyphens + .replace(/[^a-z0-9-]/g, '') // Remove non-alphanumeric characters except hyphens + .replace(/--+/g, '-') // Replace multiple consecutive hyphens with a single hyphen + .replace(/^-+|-+$/g, ''); // Trim hyphens from the beginning and end of the string +} + /** * * @param registerOrgDto @@ -70,6 +88,16 @@ export class OrganizationService { // eslint-disable-next-line camelcase async updateOrganization(updateOrgDto: IUpdateOrganization, userId: number): Promise { try { + + const organizationExist = await this.organizationRepository.checkOrganizationNameExist(updateOrgDto.name); + + if (organizationExist) { + throw new ConflictException(ResponseMessages.organisation.error.exists); + } + + const orgSlug = await this.createOrgSlug(updateOrgDto.name); + updateOrgDto.orgSlug = orgSlug; + const organizationDetails = await this.organizationRepository.updateOrganization(updateOrgDto); await this.userActivityService.createActivity(userId, organizationDetails.id, `${organizationDetails.name} organization updated`, 'Organization details updated successfully'); return organizationDetails; @@ -147,13 +175,17 @@ export class OrganizationService { } } - async getPublicProfile(payload: { id }): Promise { + async getPublicProfile(payload: { orgSlug }): Promise { try { - const query = { - id: payload.id, - publicProfile: true - }; + let query = {}; + + if (payload.orgSlug) { + query = { + orgSlug: payload.orgSlug, + publicProfile: true + }; + } const organizationDetails = await this.organizationRepository.getOrganization(query); if (!organizationDetails) { diff --git a/apps/user/interfaces/user.interface.ts b/apps/user/interfaces/user.interface.ts index 051ba3bfb..ed5febe00 100644 --- a/apps/user/interfaces/user.interface.ts +++ b/apps/user/interfaces/user.interface.ts @@ -26,6 +26,7 @@ export interface InvitationsI { export interface UserEmailVerificationDto{ email:string + username?:string } export interface userInfo{ @@ -51,4 +52,5 @@ export interface UpdateUserProfile { profileImg?: string; firstName: string, lastName: string, + isPublic: boolean, } \ No newline at end of file diff --git a/apps/user/repositories/user.repository.ts b/apps/user/repositories/user.repository.ts index cfdfc92e7..c0e070b36 100644 --- a/apps/user/repositories/user.repository.ts +++ b/apps/user/repositories/user.repository.ts @@ -7,11 +7,11 @@ import { InternalServerErrorException } from '@nestjs/common'; import { PrismaService } from '@credebl/prisma-service'; // eslint-disable-next-line camelcase import { user } from '@prisma/client'; -import { v4 as uuidv4 } from 'uuid'; interface UserQueryOptions { id?: number; // Use the appropriate type based on your data model email?: string; // Use the appropriate type based on your data model + username?: string // Add more properties if needed for other unique identifier fields }; @@ -24,12 +24,11 @@ export class UserRepository { * @param userEmailVerificationDto * @returns user email */ - async createUser(userEmailVerificationDto: UserEmailVerificationDto): Promise { + async createUser(userEmailVerificationDto: UserEmailVerificationDto, verifyCode: string): Promise { try { - const verifyCode = uuidv4(); const saveResponse = await this.prisma.user.create({ data: { - username: userEmailVerificationDto.email, + username: userEmailVerificationDto.username, email: userEmailVerificationDto.email, verificationCode: verifyCode.toString() } @@ -99,19 +98,26 @@ export class UserRepository { * @param id * @returns User profile data */ - async getUserPublicProfile(id: number): Promise { - const queryOptions: UserQueryOptions = { - id - }; - return this.findUserForPublicProfile(queryOptions); - } + async getUserPublicProfile(username: string): Promise { + + + let queryOptions: UserQueryOptions = {}; + if (username) { + queryOptions = { + username + }; + + } + return this.findUserForPublicProfile(queryOptions); + } /** * * @Body updateUserProfile * @returns Update user profile data */ - async updateUserProfile(updateUserProfile: UpdateUserProfile): Promise { + async updateUserProfile(updateUserProfile: UpdateUserProfile): Promise { + try { const userdetails = await this.prisma.user.update({ where: { @@ -120,7 +126,8 @@ export class UserRepository { data: { profileImg: updateUserProfile.profileImg, firstName: updateUserProfile.firstName, - lastName: updateUserProfile.lastName + lastName: updateUserProfile.lastName, + publicProfile: updateUserProfile?.isPublic } }); return userdetails; @@ -233,6 +240,9 @@ export class UserRepository { }, { email: queryOptions.email + }, + { + username: queryOptions.username } ] }, @@ -253,7 +263,8 @@ export class UserRepository { name: true, description: true, logoUrl: true, - website: true + website: true, + orgSlug: true }, where:{ publicProfile: true @@ -397,6 +408,7 @@ export class UserRepository { email: true, firstName: true, lastName: true, + profileImg: true, isEmailVerified: true, clientId: false, clientSecret: false, diff --git a/apps/user/src/user.controller.ts b/apps/user/src/user.controller.ts index 629bb9dcf..0fa931ccb 100644 --- a/apps/user/src/user.controller.ts +++ b/apps/user/src/user.controller.ts @@ -1,3 +1,4 @@ +import { AddPasskeyDetails, UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface'; import { AcceptRejectInvitationDto } from '../dtos/accept-reject-invitation.dto'; import { Controller } from '@nestjs/common'; @@ -5,8 +6,6 @@ import { LoginUserDto } from '../dtos/login-user.dto'; import { MessagePattern } from '@nestjs/microservices'; import { UserService } from './user.service'; import { VerifyEmailTokenDto } from '../dtos/verify-email.dto'; -import { AddPasskeyDetails, UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface'; - @Controller() export class UserController { @@ -43,7 +42,7 @@ export class UserController { } @MessagePattern({ cmd: 'get-user-public-profile' }) - async getPublicProfile(payload: { id }): Promise { + async getPublicProfile(payload: { username }): Promise { return this.userService.getPublicProfile(payload); } @MessagePattern({ cmd: 'update-user-profile' }) diff --git a/apps/user/src/user.service.ts b/apps/user/src/user.service.ts index f18f55843..5535cc342 100644 --- a/apps/user/src/user.service.ts +++ b/apps/user/src/user.service.ts @@ -32,6 +32,7 @@ import { AcceptRejectInvitationDto } from '../dtos/accept-reject-invitation.dto' import { UserActivityService } from '@credebl/user-activity'; import { SupabaseService } from '@credebl/supabase'; import { UserDevicesRepository } from '../repositories/user-device.repository'; +import { v4 as uuidv4 } from 'uuid'; @Injectable() @@ -67,7 +68,10 @@ export class UserService { throw new ConflictException(ResponseMessages.user.error.verificationAlreadySent); } - const resUser = await this.userRepository.createUser(userEmailVerificationDto); + const verifyCode = uuidv4(); + const uniqueUsername = await this.createUsername(userEmailVerificationDto.email, verifyCode); + userEmailVerificationDto.username = uniqueUsername; + const resUser = await this.userRepository.createUser(userEmailVerificationDto, verifyCode); try { await this.sendEmailForVerification(userEmailVerificationDto.email, resUser.verificationCode); @@ -82,6 +86,30 @@ export class UserService { } } + async createUsername(email: string, verifyCode: string): Promise { + + try { + // eslint-disable-next-line prefer-destructuring + const emailTrim = email.split('@')[0]; + + // Replace special characters with hyphens + const cleanedUsername = emailTrim.toLowerCase().replace(/[^a-zA-Z0-9_]/g, '-'); + + // Generate a 5-digit UUID + // eslint-disable-next-line prefer-destructuring + const uuid = verifyCode.split('-')[0]; + + // Combine cleaned username and UUID + const uniqueUsername = `${cleanedUsername}-${uuid}`; + + return uniqueUsername; + + } catch (error) { + this.logger.error(`Error in createUsername: ${JSON.stringify(error)}`); + throw new InternalServerErrorException(error.message); + } + } + /** * * @param email @@ -313,9 +341,9 @@ export class UserService { } } - async getPublicProfile(payload: { id }): Promise { + async getPublicProfile(payload: {username }): Promise { try { - const userProfile = await this.userRepository.getUserPublicProfile(payload.id); + const userProfile = await this.userRepository.getUserPublicProfile(payload.username); if (!userProfile) { throw new NotFoundException(ResponseMessages.user.error.profileNotFound); From ff795b7163d030420ed22630a5ac3025df735628 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Fri, 15 Sep 2023 12:04:32 +0530 Subject: [PATCH 2/5] refractored the GET API endoints for public profiles Signed-off-by: @nishad.shirsat --- apps/api-gateway/src/organization/organization.controller.ts | 2 +- apps/api-gateway/src/user/user.controller.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/api-gateway/src/organization/organization.controller.ts b/apps/api-gateway/src/organization/organization.controller.ts index 25934cfe1..e463cb3c0 100644 --- a/apps/api-gateway/src/organization/organization.controller.ts +++ b/apps/api-gateway/src/organization/organization.controller.ts @@ -79,7 +79,7 @@ export class OrganizationController { * @param res * @returns Users list of organization */ - @Get('/public') + @Get() @ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto }) @ApiOperation({ summary: 'Get public organization list', description: 'Get users list.' }) @ApiQuery({ diff --git a/apps/api-gateway/src/user/user.controller.ts b/apps/api-gateway/src/user/user.controller.ts index 6c18391e8..953c57cf4 100644 --- a/apps/api-gateway/src/user/user.controller.ts +++ b/apps/api-gateway/src/user/user.controller.ts @@ -119,7 +119,7 @@ export class UserController { * @param res * @returns Users list of organization */ - @Get('/public') + @Get('/public-profiles') @ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto }) @ApiOperation({ summary: 'Get users list', description: 'Get users list.' }) @ApiQuery({ From 2538ec6fbc056514fa35186d579870153d4924d7 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Fri, 15 Sep 2023 12:11:13 +0530 Subject: [PATCH 3/5] refactored the organization GET API public profiles Signed-off-by: @nishad.shirsat --- apps/api-gateway/src/organization/organization.controller.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api-gateway/src/organization/organization.controller.ts b/apps/api-gateway/src/organization/organization.controller.ts index e463cb3c0..32d4cec98 100644 --- a/apps/api-gateway/src/organization/organization.controller.ts +++ b/apps/api-gateway/src/organization/organization.controller.ts @@ -79,7 +79,7 @@ export class OrganizationController { * @param res * @returns Users list of organization */ - @Get() + @Get('/public-profiles') @ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto }) @ApiOperation({ summary: 'Get public organization list', description: 'Get users list.' }) @ApiQuery({ From 1edeeaf8af0b516aa3d9648530bd00fd84d0f563 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Fri, 15 Sep 2023 12:28:28 +0530 Subject: [PATCH 4/5] solved the regix expression grouping issue. Signed-off-by: @nishad.shirsat --- apps/organization/src/organization.service.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/organization/src/organization.service.ts b/apps/organization/src/organization.service.ts index ddafd90d8..10ed3e6cc 100644 --- a/apps/organization/src/organization.service.ts +++ b/apps/organization/src/organization.service.ts @@ -48,7 +48,7 @@ export class OrganizationService { throw new ConflictException(ResponseMessages.organisation.error.exists); } - const orgSlug = await this.createOrgSlug(createOrgDto.name); + const orgSlug = this.createOrgSlug(createOrgDto.name); createOrgDto.orgSlug = orgSlug; const organizationDetails = await this.organizationRepository.createOrganization(createOrgDto); @@ -76,7 +76,7 @@ export class OrganizationService { .replace(/\s+/g, '-') // Replace spaces with hyphens .replace(/[^a-z0-9-]/g, '') // Remove non-alphanumeric characters except hyphens .replace(/--+/g, '-') // Replace multiple consecutive hyphens with a single hyphen - .replace(/^-+|-+$/g, ''); // Trim hyphens from the beginning and end of the string + .replace(/[^-+|-+$]/g, ''); // Trim hyphens from the beginning and end of the string } /** From 1446b1b8b981e2acf2789e86da1a9f37a8108f47 Mon Sep 17 00:00:00 2001 From: "@nishad.shirsat" Date: Fri, 15 Sep 2023 13:55:32 +0530 Subject: [PATCH 5/5] resolved the comments on the PR Signed-off-by: @nishad.shirsat --- .../repositories/organization.repository.ts | 2 +- apps/organization/src/organization.service.ts | 15 ++++++--------- apps/user/repositories/user.repository.ts | 10 +++------- apps/user/src/user.controller.ts | 4 ++-- apps/user/src/user.service.ts | 6 +++--- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/apps/organization/repositories/organization.repository.ts b/apps/organization/repositories/organization.repository.ts index 8339b220a..f20c85219 100644 --- a/apps/organization/repositories/organization.repository.ts +++ b/apps/organization/repositories/organization.repository.ts @@ -245,7 +245,7 @@ export class OrganizationRepository { } } - async getOrganization(queryObject: object): Promise { + async getOrganization(queryObject: object): Promise { try { return this.prisma.organisation.findFirst({ where: { diff --git a/apps/organization/src/organization.service.ts b/apps/organization/src/organization.service.ts index 10ed3e6cc..5f1daee51 100644 --- a/apps/organization/src/organization.service.ts +++ b/apps/organization/src/organization.service.ts @@ -175,17 +175,14 @@ export class OrganizationService { } } - async getPublicProfile(payload: { orgSlug }): Promise { + async getPublicProfile(payload: { orgSlug: string }): Promise { + const {orgSlug} = payload; try { - let query = {}; - - if (payload.orgSlug) { - query = { - orgSlug: payload.orgSlug, - publicProfile: true - }; - } + const query = { + orgSlug, + publicProfile: true + }; const organizationDetails = await this.organizationRepository.getOrganization(query); if (!organizationDetails) { diff --git a/apps/user/repositories/user.repository.ts b/apps/user/repositories/user.repository.ts index c0e070b36..0743b628b 100644 --- a/apps/user/repositories/user.repository.ts +++ b/apps/user/repositories/user.repository.ts @@ -99,15 +99,11 @@ export class UserRepository { * @returns User profile data */ async getUserPublicProfile(username: string): Promise { - - - let queryOptions: UserQueryOptions = {}; - if (username) { - queryOptions = { + + const queryOptions: UserQueryOptions = { username }; - } return this.findUserForPublicProfile(queryOptions); } @@ -116,7 +112,7 @@ export class UserRepository { * @Body updateUserProfile * @returns Update user profile data */ - async updateUserProfile(updateUserProfile: UpdateUserProfile): Promise { + async updateUserProfile(updateUserProfile: UpdateUserProfile): Promise { try { const userdetails = await this.prisma.user.update({ diff --git a/apps/user/src/user.controller.ts b/apps/user/src/user.controller.ts index 0fa931ccb..9d94f00e0 100644 --- a/apps/user/src/user.controller.ts +++ b/apps/user/src/user.controller.ts @@ -1,4 +1,4 @@ -import { AddPasskeyDetails, UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface'; +import { AddPasskeyDetails, UpdateUserProfile, UserEmailVerificationDto, UserI, userInfo } from '../interfaces/user.interface'; import { AcceptRejectInvitationDto } from '../dtos/accept-reject-invitation.dto'; import { Controller } from '@nestjs/common'; @@ -42,7 +42,7 @@ export class UserController { } @MessagePattern({ cmd: 'get-user-public-profile' }) - async getPublicProfile(payload: { username }): Promise { + async getPublicProfile(payload: { username }): Promise { return this.userService.getPublicProfile(payload); } @MessagePattern({ cmd: 'update-user-profile' }) diff --git a/apps/user/src/user.service.ts b/apps/user/src/user.service.ts index 5535cc342..96753ee0c 100644 --- a/apps/user/src/user.service.ts +++ b/apps/user/src/user.service.ts @@ -27,7 +27,7 @@ import { sendEmail } from '@credebl/common/send-grid-helper-file'; import { user } from '@prisma/client'; import { Inject } from '@nestjs/common'; import { HttpException } from '@nestjs/common'; -import { AddPasskeyDetails, InvitationsI, UpdateUserProfile, UserEmailVerificationDto, userInfo } from '../interfaces/user.interface'; +import { AddPasskeyDetails, InvitationsI, UpdateUserProfile, UserEmailVerificationDto, UserI, userInfo } from '../interfaces/user.interface'; import { AcceptRejectInvitationDto } from '../dtos/accept-reject-invitation.dto'; import { UserActivityService } from '@credebl/user-activity'; import { SupabaseService } from '@credebl/supabase'; @@ -341,7 +341,7 @@ export class UserService { } } - async getPublicProfile(payload: {username }): Promise { + async getPublicProfile(payload: { username }): Promise { try { const userProfile = await this.userRepository.getUserPublicProfile(payload.username); @@ -356,7 +356,7 @@ export class UserService { } } - async updateUserProfile(updateUserProfileDto: UpdateUserProfile): Promise { + async updateUserProfile(updateUserProfileDto: UpdateUserProfile): Promise { try { return this.userRepository.updateUserProfile(updateUserProfileDto); } catch (error) {