Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: GET API of platform config settings #235

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions apps/api-gateway/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ export class UserController {

}

@Get('/platform-settings')
@ApiOperation({ summary: 'Get all platform and ecosystem settings', description: 'Get all platform and ecosystem settings' })
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@Roles(OrgRoles.PLATFORM_ADMIN)
@ApiBearerAuth()
async getPlatformSettings(@Res() res: Response): Promise<Response> {
const settings = await this.userService.getPlatformSettings();

const finalResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.user.success.fetchPlatformSettings,
data: settings.response
};

return res.status(HttpStatus.OK).json(finalResponse);

}

@Get('/activity')
@ApiOperation({
summary: 'organization invitations',
Expand Down
4 changes: 4 additions & 0 deletions apps/api-gateway/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ export class UserService extends BaseService {
const payload = { platformSettings };
return this.sendNats(this.serviceProxy, 'update-platform-settings', payload);
}

async getPlatformSettings(): Promise<{ response: object }> {
return this.sendNats(this.serviceProxy, 'fetch-platform-settings', '');
}
}
14 changes: 14 additions & 0 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ export class EcosystemRepository {
}
}

async checkEcosystemNameExist(name: string): Promise<ecosystem> {
try {
return this.prisma.ecosystem.findFirst({
where: {
name
}
});
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}


/**
*
* @param orgId
Expand Down
6 changes: 6 additions & 0 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export class EcosystemService {
// eslint-disable-next-line camelcase
async createEcosystem(createEcosystemDto: CreateEcosystem): Promise<object> {

const ecosystemExist = await this.ecosystemRepository.checkEcosystemNameExist(createEcosystemDto.name);

if (ecosystemExist) {
throw new ConflictException(ResponseMessages.ecosystem.error.exists);
}

const isMultiEcosystemEnabled = await this.ecosystemRepository.getSpecificEcosystemConfig(EcosystemConfigSettings.MULTI_ECOSYSTEM);

if (isMultiEcosystemEnabled && 'false' === isMultiEcosystemEnabled.value) {
Expand Down
22 changes: 21 additions & 1 deletion apps/user/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,5 +551,25 @@ export class UserRepository {
throw new InternalServerErrorException(error);
}
}


async getPlatformSettings(): Promise<object> {
try {
const getPlatformSettingsList = await this.prisma.platform_config.findMany();
return getPlatformSettingsList;
} catch (error) {
this.logger.error(`error in getPlatformSettings: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}

async getEcosystemSettings(): Promise<object> {
try {
const getEcosystemSettingsList = await this.prisma.ecosystem_config.findMany();
return getEcosystemSettingsList;
} catch (error) {
this.logger.error(`error in getEcosystemSettings: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}

}
6 changes: 6 additions & 0 deletions apps/user/src/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,10 @@ export class UserController {
async updatePlatformSettings(payload: { platformSettings: PlatformSettingsI }): Promise<string> {
return this.userService.updatePlatformSettings(payload.platformSettings);
}

@MessagePattern({ cmd: 'fetch-platform-settings' })
async getPlatformEcosystemSettings(): Promise<object> {
return this.userService.getPlatformEcosystemSettings();
}

}
27 changes: 27 additions & 0 deletions apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,31 @@ export class UserService {
throw new RpcException(error.response ? error.response : error);
}
}

async getPlatformEcosystemSettings(): Promise<object> {
try {

const platformSettings = {};
const platformConfigSettings = await this.userRepository.getPlatformSettings();

if (!platformConfigSettings) {
throw new BadRequestException(ResponseMessages.user.error.platformSetttingsNotFound);
}

const ecosystemConfigSettings = await this.userRepository.getEcosystemSettings();

if (!ecosystemConfigSettings) {
throw new BadRequestException(ResponseMessages.user.error.ecosystemSetttingsNotFound);
}

platformSettings['platform_config'] = platformConfigSettings;
platformSettings['ecosystem_config'] = ecosystemConfigSettings;

return platformSettings;

} catch (error) {
this.logger.error(`update platform settings: ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
}
}
}
6 changes: 5 additions & 1 deletion libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ export const ResponseMessages = {
checkEmail: 'User email checked successfully.',
sendVerificationCode: 'Verification code has been sent sucessfully to the mail. Please verify',
userActivity: 'User activities fetched successfully',
platformEcosystemettings: 'Platform and ecosystem settings updated'
platformEcosystemettings: 'Platform and ecosystem settings updated',
fetchPlatformSettings: 'Platform settings fetched'
},
error: {
exists: 'User already exists',
profileNotFound: 'User public profile not found',
notUpdatePlatformSettings: 'Unable to update platform config settings',
platformSetttingsNotFound: 'Unable to get platform settings',
ecosystemSetttingsNotFound: 'Unable to get ecosystem settings',
notUpdateEcosystemSettings: 'Unable to update ecosystem config settings',
verificationAlreadySent: 'The verification link has already been sent to your email address',
emailSend: 'Unable to send email to the user',
Expand Down Expand Up @@ -219,6 +222,7 @@ export const ResponseMessages = {
},
error: {
notCreated: 'Error while creating ecosystem',
exists: 'An ecosystem name is already exist',
update: 'Error while updating ecosystem',
invalidInvitationStatus: 'Invalid invitation status',
invitationNotFound: 'Ecosystem Invitation not found',
Expand Down
4 changes: 3 additions & 1 deletion libs/org-roles/repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common
import { PrismaService } from '@credebl/prisma-service';
// eslint-disable-next-line camelcase
import { org_roles } from '@prisma/client';
import { OrgRoles } from '../enums';

@Injectable()
export class OrgRolesRepository {
Expand All @@ -28,7 +29,8 @@ export class OrgRolesRepository {
async getOrgRoles(): Promise<org_roles[]> {
try {
const roleDetails = await this.prisma.org_roles.findMany();
return roleDetails;
const filteredRoles = roleDetails.filter(role => role.name !== OrgRoles.PLATFORM_ADMIN);
return filteredRoles;
} catch (error) {
this.logger.error(`In get org-roles repository: ${JSON.stringify(error)}`);
throw new InternalServerErrorException('Bad Request');
Expand Down