Skip to content

Commit

Permalink
refactor: ecosystem lead details included ecosystem dashboard (#156)
Browse files Browse the repository at this point in the history
* worked on the ecosystem lead details

Signed-off-by: Nishad <[email protected]>

* removed the unnecessary code and comments

Signed-off-by: Nishad <[email protected]>

---------

Signed-off-by: Nishad <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
nishad-ayanworks authored and KulkarniShashank committed Sep 11, 2024
1 parent 3a9c554 commit 274fefb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
22 changes: 21 additions & 1 deletion apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,27 @@ export class EcosystemController {
return res.status(HttpStatus.OK).json(finalResponse);
}

@Get('/users/invitations')
@Get('/:ecosystemId/:orgId/dashboard')
@ApiOperation({ summary: 'Get ecosystem dashboard details', description: 'Get ecosystem dashboard details' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), OrgRolesGuard, EcosystemRolesGuard)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_OWNER, EcosystemRoles.ECOSYSTEM_LEAD, EcosystemRoles.ECOSYSTEM_MEMBER)
@ApiBearerAuth()

async getEcosystemDashboardDetails(@Param('ecosystemId') ecosystemId: string, @Param('orgId') orgId: string, @Res() res: Response): Promise<Response> {

const getEcosystemDetails = await this.ecosystemService.getEcosystemDashboardDetails(ecosystemId, orgId);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.ecosystem.success.getEcosystemDashboard,
data: getEcosystemDetails.response
};
return res.status(HttpStatus.OK).json(finalResponse);

}

@Get('/:orgId/users/invitations')
@ApiOperation({ summary: 'Get received ecosystem invitations', description: 'Get received ecosystem invitations' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
Expand Down
8 changes: 5 additions & 3 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export class EcosystemRepository {
* @returns Get ecosystem dashboard card count
*/

async getEcosystemDashboardDetails(ecosystemId: string): Promise<object> {
async getEcosystemDashboardDetails(ecosystemId: string): Promise<{membersCount: number; endorsementsCount: number}> {
try {
const membersCount = await this.getEcosystemMembersCount(ecosystemId);
const endorsementsCount = await this.getEcosystemEndorsementsCount(ecosystemId);
Expand Down Expand Up @@ -513,15 +513,17 @@ export class EcosystemRepository {


async fetchEcosystemOrg(
payload: { ecosystemId: string, orgId: string }
payload: object
): Promise<object> {

return this.prisma.ecosystem_orgs.findFirst({
where: {
...payload
},
select: {
ecosystemRole: true
ecosystem: true,
ecosystemRole: true,
orgName: true
}
});

Expand Down
25 changes: 24 additions & 1 deletion apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,30 @@ export class EcosystemService {
*/
async getEcosystemDashboardDetails(ecosystemId: string): Promise<object> {
try {
return await this.ecosystemRepository.getEcosystemDashboardDetails(ecosystemId);
const endorseMemberCount = await this.ecosystemRepository.getEcosystemDashboardDetails(ecosystemId);

const query = {
ecosystemId,
ecosystemRole: {
name: EcosystemRoles.ECOSYSTEM_LEAD
}
};

const ecosystemDetails = await this.ecosystemRepository.fetchEcosystemOrg(
query
);

const dashboardDetails = {
ecosystem: ecosystemDetails['ecosystem'],
membersCount: endorseMemberCount.membersCount,
endorsementsCount: endorseMemberCount.endorsementsCount,
ecosystemLead:{
role: ecosystemDetails['ecosystemRole']['name'],
orgName: ecosystemDetails['orgName']
}
};

return dashboardDetails;
} catch (error) {
this.logger.error(`In ecosystem dashboard details : ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
Expand Down

0 comments on commit 274fefb

Please sign in to comment.