Skip to content
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
24 changes: 23 additions & 1 deletion apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export class EcosystemController {
description: 'Template details fetched successfully'
})
async getTemplateByIntentId(
@Param(
@Param(
'orgId',
TrimStringParamPipe,
new ParseUUIDPipe({
Expand Down Expand Up @@ -944,4 +944,26 @@ export class EcosystemController {
data: intent
});
}

@Get('/dashboard/summary')
@Roles(OrgRoles.PLATFORM_ADMIN)
@UseGuards(AuthGuard('jwt'), EcosystemRolesGuard)
@ApiBearerAuth()
@ApiOperation({
summary: 'Get Count for Ecosystem dashboard',
description: 'Get Count for Ecosystem dashboard'
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Dashboard count fetched successfully'
})
async getDashboardCountEcosystem(@Res() res: Response): Promise<Response> {
const dashboard = await this.ecosystemService.getDashboardCountEcosystem();

return res.status(HttpStatus.OK).json({
statusCode: HttpStatus.OK,
message: ResponseMessages.ecosystem.success.dashboard,
data: dashboard
});
}
}
13 changes: 11 additions & 2 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
IEcosystemDashboard,
IEcosystemInvitation,
IEcosystemMemberInvitations,
IGetAllOrgs
IGetAllOrgs,
IPlatformDashboardCount
} from 'apps/ecosystem/interfaces/ecosystem.interfaces';
import { CreateEcosystemDto } from 'apps/ecosystem/dtos/create-ecosystem-dto';
// eslint-disable-next-line camelcase
Expand Down Expand Up @@ -40,7 +41,11 @@ export class EcosystemService {
* @param userId
* @returns All ecosystems from platform
*/
async getEcosystems(userId: string, pageDetail: IPaginationSortingDto, orgId:string): Promise<PaginatedResponse<IEcosystem>> {
async getEcosystems(
userId: string,
pageDetail: IPaginationSortingDto,
orgId: string
): Promise<PaginatedResponse<IEcosystem>> {
return this.natsClient.sendNatsMessage(this.serviceProxy, 'get-ecosystems', { userId, pageDetail, orgId });
}

Expand Down Expand Up @@ -229,4 +234,8 @@ export class EcosystemService {
userId
});
}

async getDashboardCountEcosystem(): Promise<IPlatformDashboardCount> {
return this.natsClient.sendNatsMessage(this.serviceProxy, 'get-platform-admin-dashboard-count', {});
}
}
32 changes: 30 additions & 2 deletions apps/api-gateway/src/platform/platform.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { CreateEcosystemInvitationDto } from '../ecosystem/dtos/send-ecosystem-invitation';
import { EnableEcosystemDto } from '../ecosystem/dtos/enable-ecosystem';
import { EcosystemFeatureGuard } from '../authz/guards/ecosystem-feature-guard';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
import { EcosystemRolesGuard } from '../authz/guards/ecosystem-roles.guard';

@Controller('')
@UseFilters(CustomExceptionFilter)
Expand Down Expand Up @@ -269,8 +271,12 @@ export class PlatformController {
@Roles(OrgRoles.PLATFORM_ADMIN)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard, EcosystemFeatureGuard)
@ApiBearerAuth()
async getInvitations(@User() reqUser: user, @Res() res: Response): Promise<Response> {
const invitations = await this.platformService.getInvitationsByUserId(reqUser.id);
async getInvitations(
@User() reqUser: user,
@Res() res: Response,
@Query() pageDto: PaginationDto
): Promise<Response> {
const invitations = await this.platformService.getInvitationsByUserId(reqUser.id, pageDto);

return res.status(HttpStatus.OK).json({
statusCode: HttpStatus.OK,
Expand Down Expand Up @@ -308,4 +314,26 @@ export class PlatformController {
};
return res.status(HttpStatus.OK).json(finalResponse);
}

@Get('/ecosystem/status')
@ApiOperation({
summary: 'Get ecosystem enabled/disabled status',
description: 'Get ecosystem enabled/disabled status'
})
@ApiResponse({
status: HttpStatus.OK,
description: 'Ecosystem status fetched successfully'
})
@Roles(OrgRoles.PLATFORM_ADMIN)
@UseGuards(AuthGuard('jwt'), EcosystemRolesGuard)
@ApiBearerAuth()
async getEcosystemEnableStatus(@Res() res: Response): Promise<Response> {
const ecosystemStatus = await this.platformService.getEcosystemEnableStatus();

return res.status(HttpStatus.OK).json({
statusCode: HttpStatus.OK,
message: ResponseMessages.ecosystem.success.ecosystemStatus,
data: ecosystemStatus
});
}
}
15 changes: 13 additions & 2 deletions apps/api-gateway/src/platform/platform.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { IPlatformCredDefsData } from '@credebl/common/interfaces/cred-def.inter
import { NATSClient } from '@credebl/common/NATSClient';
import { ClientProxy } from '@nestjs/microservices';
import { IEcosystemInvitations } from 'apps/ecosystem/interfaces/ecosystem.interfaces';
import { IPaginationSortingDto, PaginatedResponse } from '@credebl/common/interfaces/interface';

@Injectable()
export class PlatformService extends BaseService {
Expand Down Expand Up @@ -62,8 +63,14 @@ export class PlatformService extends BaseService {
* @param userId
* @returns Get invitations
*/
async getInvitationsByUserId(userId: string): Promise<IEcosystemInvitations[]> {
return this.natsClient.sendNatsMessage(this.platformServiceProxy, 'get-ecosystem-invitations-by-user', { userId });
async getInvitationsByUserId(
userId: string,
pageDetail: IPaginationSortingDto
): Promise<PaginatedResponse<IEcosystemInvitations>> {
return this.natsClient.sendNatsMessage(this.platformServiceProxy, 'get-ecosystem-invitations-by-user', {
userId,
pageDetail
});
}

/**
Expand All @@ -75,4 +82,8 @@ export class PlatformService extends BaseService {
platformAdminId
});
}

async getEcosystemEnableStatus(): Promise<boolean> {
return this.natsClient.sendNatsMessage(this.platformServiceProxy, 'get-ecosystem-enable-status', {});
}
}
13 changes: 13 additions & 0 deletions apps/ecosystem/interfaces/ecosystem.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export interface IEcosystemInvitations {
createdBy: string;
organization?: IEcosystemOrg;
invitedOrg?: string;
orgStatus?: string;
}

export interface IEcosystemOrg {
Expand Down Expand Up @@ -201,6 +202,18 @@ export interface IGetAllOrgUser {
username: string | null;
}

export interface IGetEcosystemOrgStatus {
ecosystemId: string;
orgId: string;
status: string;
}

export type EcosystemInvitationRoles = OrgRoles.ECOSYSTEM_LEAD | OrgRoles.ECOSYSTEM_MEMBER;

export type PrismaExecutor = Prisma.TransactionClient | PrismaClient;

export interface IPlatformDashboardCount {
ecosystem: number;
invitations: number;
activeOrgs: number;
}
125 changes: 95 additions & 30 deletions apps/ecosystem/repositories/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
IEcosystemDashboard,
IEcosystemInvitation,
IGetAllOrgs,
IGetEcosystemOrgStatus,
IPlatformDashboardCount,
PrismaExecutor
} from '../interfaces/ecosystem.interfaces';
import {
Expand Down Expand Up @@ -93,41 +95,44 @@ export class EcosystemRepository {
}

async getInvitationsByUserId(
userId: string
userId: string,
pageDetail: IPaginationSortingDto
// eslint-disable-next-line camelcase
): Promise<ecosystem_invitations[]> {
): Promise<PaginatedResponse<ecosystem_invitations>> {
try {
return await this.prisma.ecosystem_invitations.findMany({
where: {
createdBy: userId
},
include: {
ecosystem: {
select: {
id: true,
name: true,
description: true,
createDateTime: true
const whereClause = {
createdBy: userId,
deletedAt: null
};
Comment thread
sujitaw marked this conversation as resolved.
const [data, count] = await this.prisma.$transaction([
this.prisma.ecosystem_invitations.findMany({
where: whereClause,
include: {
ecosystem: {
select: {
id: true,
name: true,
description: true,
createDateTime: true
}
},
organisation: {
select: {
name: true
}
}
},
user: {
select: {
id: true,
firstName: true,
lastName: true,
email: true
}
orderBy: {
createDateTime: 'desc'
},
organisation: {
select: {
name: true
}
}
},
orderBy: {
createDateTime: 'desc'
}
});
take: pageDetail.pageSize,
skip: (pageDetail.pageNumber - 1) * pageDetail.pageSize
}),

this.prisma.ecosystem_invitations.count({ where: whereClause })
]);
const totalPages = Math.ceil(count / pageDetail.pageSize);
return { totalPages, data };
} catch (error) {
this.logger.error('getInvitationsByUserId error', error);
throw new InternalServerErrorException(ResponseMessages.ecosystem.error.fetchInvitationsFailed);
Expand Down Expand Up @@ -1491,4 +1496,64 @@ export class EcosystemRepository {
throw error;
}
}

async getEcosystemOrgsByOrgIdAndEcosystemId(
orgId: string[],
ecosystemId: string[]
): Promise<IGetEcosystemOrgStatus[]> {
try {
return await this.prisma.ecosystem_orgs.findMany({
where: {
orgId: { in: orgId },
ecosystemId: { in: ecosystemId },
deletedAt: null
},
select: {
orgId: true,
ecosystemId: true,
status: true
}
});
} catch (error) {
this.logger.error(`getEcosystemOrgsByOrgIdAndEcosystemId error: ${error}`);
throw error;
}
}
Comment thread
sujitaw marked this conversation as resolved.

async getDashBoardCountPlatformAdmin(): Promise<IPlatformDashboardCount> {
try {
const data = await this.prisma.$transaction([
this.prisma.ecosystem.count({ where: { deletedAt: null } }),
this.prisma.ecosystem_invitations.count({
where: {
type: InviteType.ECOSYSTEM,
deletedAt: null
}
}),
this.prisma.ecosystem_orgs.count({
where: {
status: EcosystemOrgStatus.ACTIVE,
deletedAt: null
}
})
Comment thread
sujitaw marked this conversation as resolved.
]);
const [ecosystem, invitations, activeOrgs] = data;
return { ecosystem, invitations, activeOrgs };
} catch (error) {
this.logger.error(`getDashBoardCountPlatformAdmin error: ${error}`);
throw error;
}
}

async getEcosystemEnableStatus(): Promise<boolean> {
try {
const data = await this.prisma.platform_config.findFirst({
select: { isEcosystemEnabled: true }
});
return data?.isEcosystemEnabled ?? false;
} catch (error) {
this.logger.error(`getEcosystemEnableStatus error: ${error}`);
throw error;
}
}
Comment thread
sujitaw marked this conversation as resolved.
}
20 changes: 17 additions & 3 deletions apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
IEcosystemInvitation,
IEcosystemInvitations,
IEcosystemMemberInvitations,
IGetAllOrgs
IGetAllOrgs,
IPlatformDashboardCount
} from '../interfaces/ecosystem.interfaces';
import {
IIntentTemplateList,
Expand Down Expand Up @@ -47,8 +48,11 @@ export class EcosystemController {
* @returns List of ecosystem invitations
*/
@MessagePattern({ cmd: 'get-ecosystem-invitations-by-user' })
async getInvitationsByUserId(payload: { userId: string }): Promise<IEcosystemInvitations[]> {
return this.ecosystemService.getInvitationsByUserId(payload.userId);
async getInvitationsByUserId(payload: {
userId: string;
pageDetail: IPaginationSortingDto;
}): Promise<PaginatedResponse<IEcosystemInvitations>> {
return this.ecosystemService.getInvitationsByUserId(payload.userId, payload.pageDetail);
}

/**
Expand Down Expand Up @@ -325,4 +329,14 @@ export class EcosystemController {
}): Promise<{ message: string }> {
return this.ecosystemService.updateEcosystemConfig(payload);
}

@MessagePattern({ cmd: 'get-platform-admin-dashboard-count' })
async getDashboardCountEcosystem(): Promise<IPlatformDashboardCount> {
return this.ecosystemService.getDashboardCountEcosystem();
}

@MessagePattern({ cmd: 'get-ecosystem-enable-status' })
async getEcosystemEnableStatus(): Promise<boolean> {
return this.ecosystemService.getEcosystemEnableStatus();
}
}
Loading