Skip to content

Commit

Permalink
feat: fetch org activity count (#765)
Browse files Browse the repository at this point in the history
* feat: get organization activity count

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

* reafctor: org activity interface

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>

---------

Signed-off-by: bhavanakarwade <bhavana.karwade@ayanworks.com>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 6, 2024
1 parent 8c6dc9a commit 3d8e88f
Show file tree
Hide file tree
Showing 19 changed files with 321 additions and 9 deletions.
19 changes: 19 additions & 0 deletions apps/api-gateway/src/organization/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,25 @@ export class OrganizationController {

}

@Get('/activity-count/:orgId')
@ApiOperation({ summary: 'Get organization references count', description: 'Get organization references count by org Id' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiBearerAuth()
@Roles(OrgRoles.OWNER)
async getOrganizationActivityCount(@Param('orgId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidOrgId); }})) orgId: string, @Res() res: Response, @User() reqUser: user): Promise<Response> {

const getOrganization = await this.organizationService.getOrganizationActivityCount(orgId, reqUser.id);

const finalResponse: IResponse = {
statusCode: HttpStatus.OK,
message: ResponseMessages.organisation.success.getOrganizationActivity,
data: getOrganization
};
return res.status(HttpStatus.OK).json(finalResponse);

}

@Get('/:orgId/invitations')
@ApiOperation({ summary: 'Get all invitations', description: 'Get all invitations' })
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
Expand Down
7 changes: 6 additions & 1 deletion apps/api-gateway/src/organization/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { UpdateOrganizationDto } from './dtos/update-organization-dto';
import { organisation, user } from '@prisma/client';
import { IDidList, IGetOrgById, IGetOrganization } from 'apps/organization/interfaces/organization.interface';
import { IOrgUsers } from 'apps/user/interfaces/user.interface';
import { IOrgCredentials, IOrganization, IOrganizationInvitations, IOrganizationDashboard, IDeleteOrganization } from '@credebl/common/interfaces/organization.interface';
import { IOrgCredentials, IOrganization, IOrganizationInvitations, IOrganizationDashboard, IDeleteOrganization, IOrgActivityCount } from '@credebl/common/interfaces/organization.interface';
import { ClientCredentialsDto } from './dtos/client-credentials.dto';
import { IAccessTokenData } from '@credebl/common/interfaces/interface';
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
Expand Down Expand Up @@ -140,6 +140,11 @@ export class OrganizationService extends BaseService {
return this.sendNatsMessage(this.serviceProxy, 'get-organization-dashboard', payload);
}

async getOrganizationActivityCount(orgId: string, userId: string): Promise<IOrgActivityCount> {
const payload = { orgId, userId };
return this.sendNatsMessage(this.serviceProxy, 'get-organization-activity-count', payload);
}

/**
*
* @param
Expand Down
6 changes: 6 additions & 0 deletions apps/connection/src/connection.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export class ConnectionController {
return this.connectionService.getConnectionsById(user, connectionId, orgId);
}

@MessagePattern({ cmd: 'get-connection-records' })
async getConnectionRecordsByOrgId(payload: { orgId: string, userId: string }): Promise<number> {
const { orgId } = payload;
return this.connectionService.getConnectionRecords(orgId);
}

@MessagePattern({ cmd: 'receive-invitation-url' })
async receiveInvitationUrl(payload: IReceiveInvitationByUrlOrg): Promise<IReceiveInvitationResponse> {
const { user, receiveInvitationUrl, orgId } = payload;
Expand Down
16 changes: 16 additions & 0 deletions apps/connection/src/connection.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ export class ConnectionRepository {
}
}


async getConnectionRecordsCount(orgId: string): Promise<number> {
try {
const connectionRecordsCount = await this.prisma.connections.count({
where: {
orgId
}
});
return connectionRecordsCount;
} catch (error) {
this.logger.error(`[get connection records by org Id] - error: ${JSON.stringify(error)}`);
throw error;
}
}


/**
* Description: Save connection details
* @param connectionInvitation
Expand Down
12 changes: 12 additions & 0 deletions apps/connection/src/connection.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ export class ConnectionService {
}
}

async getConnectionRecords(orgId: string): Promise<number> {
try {
return await this.connectionRepository.getConnectionRecordsCount(orgId);
} catch (error) {

this.logger.error(
`[getConnectionRecords ] [NATS call]- error in get connection records count : ${JSON.stringify(error)}`
);
throw new RpcException(error.response ? error.response : error);
}
}

/**
* Description: Fetch connection invitaion by referenceId
* @param referenceId
Expand Down
6 changes: 6 additions & 0 deletions apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ export class EcosystemController {
return this.ecosystemService.acceptRejectEcosystemInvitations(payload.acceptRejectInvitation, payload.userEmail);
}

@MessagePattern({ cmd: 'get-ecosystem-records' })
async getEcosystemsByOrgId(payload: { orgId: string, userId: string }): Promise<number> {
const { orgId } = payload;
return this.ecosystemService.getEcosystems(orgId);
}

@MessagePattern({ cmd: 'get-sent-invitations-ecosystemId' })
async getInvitationsByOrgId(@Body() payload: FetchInvitationsPayload): Promise<IEcosystemInvitation> {
return this.ecosystemService.getInvitationsByEcosystemId(payload);
Expand Down
18 changes: 18 additions & 0 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,24 @@ export class EcosystemRepository {
}
}

async getEcosystemsCount(orgId: string): Promise<number> {
try {
const ecosystemsCount = await this.prisma.ecosystem.count({
where: {
ecosystemOrgs: {
some: {
orgId
}
}
}
});
return ecosystemsCount;
} catch (error) {
this.logger.error(`[get all ecosystems by org Id] - error: ${JSON.stringify(error)}`);
throw error;
}
}

async checkOrgExists(orgId: string): Promise<organisation> {
try {
const isOrgExists = await this.prisma.organisation.findUnique({
Expand Down
13 changes: 13 additions & 0 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ export class EcosystemService {
return orgData;
}


async getEcosystems(orgId: string): Promise<number> {
try {
return await this.ecosystemRepository.getEcosystemsCount(orgId);
} catch (error) {

this.logger.error(
`[getEcosystemsCount ] [NATS call]- error in get ecosystems count : ${JSON.stringify(error)}`
);
throw new RpcException(error.response ? error.response : error);
}
}

/**
*
* @param editEcosystemDto
Expand Down
6 changes: 6 additions & 0 deletions apps/issuance/src/issuance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { OOBIssueCredentialDto } from 'apps/api-gateway/src/issuance/dtos/issuan
export class IssuanceController {
constructor(private readonly issuanceService: IssuanceService) { }

@MessagePattern({ cmd: 'get-issuance-records' })
async getIssuanceRecordsByOrgId(payload: { orgId: string, userId: string }): Promise<number> {
const { orgId } = payload;
return this.issuanceService.getIssuanceRecords(orgId);
}

@MessagePattern({ cmd: 'send-credential-create-offer' })
async sendCredentialCreateOffer(payload: IIssuance): Promise<PromiseSettledResult<ICreateOfferResponse>[]> {
return this.issuanceService.sendCredentialCreateOffer(payload);
Expand Down
14 changes: 14 additions & 0 deletions apps/issuance/src/issuance.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ export class IssuanceRepository {
}
}

async getIssuanceRecordsCount(orgId: string): Promise<number> {
try {
const issuanceRecordsCount = await this.prisma.credentials.count({
where: {
orgId
}
});
return issuanceRecordsCount;
} catch (error) {
this.logger.error(`[get issuance records by org Id] - error: ${JSON.stringify(error)}`);
throw error;
}
}

async getOrganizationByTenantId(tenantId: string): Promise<org_agents> {
try {
return this.prisma.org_agents.findFirst({
Expand Down
12 changes: 12 additions & 0 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export class IssuanceService {
@Inject(CACHE_MANAGER) private cacheService: Cache
) { }

async getIssuanceRecords(orgId: string): Promise<number> {
try {
return await this.issuanceRepository.getIssuanceRecordsCount(orgId);
} catch (error) {

this.logger.error(
`[getIssuanceRecords ] [NATS call]- error in get issuance records count : ${JSON.stringify(error)}`
);
throw new RpcException(error.response ? error.response : error);
}
}

async sendCredentialCreateOffer(payload: IIssuance): Promise<PromiseSettledResult<ICreateOfferResponse>[]> {
try {
const { orgId, credentialDefinitionId, comment, credentialData } = payload || {};
Expand Down
14 changes: 14 additions & 0 deletions apps/organization/repositories/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,20 @@ export class OrganizationRepository {
}
}


async getOrgInvitationsCount(orgId: string): Promise<number> {
try {
return this.prisma.org_invitations.count({
where: {
orgId
}
});
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}

async getOrgInvitationsPagination(queryObject: object, pageNumber: number, pageSize: number): Promise<IOrganizationInvitations> {
try {
const result = await this.prisma.$transaction([
Expand Down
11 changes: 7 additions & 4 deletions apps/organization/src/organization.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Controller, Logger } from '@nestjs/common';

import { Controller, Logger, Body } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { OrganizationService } from './organization.service';
import { Body } from '@nestjs/common';
import { CreateOrganizationDto } from '../dtos/create-organization.dto';
import { BulkSendInvitationDto } from '../dtos/send-invitation.dto';
import { UpdateInvitationDto } from '../dtos/update-invitation.dt';
import { IDidList, IGetOrgById, IGetOrganization, IUpdateOrganization, Payload } from '../interfaces/organization.interface';
import { IOrgCredentials, IOrganizationInvitations, IOrganization, IOrganizationDashboard, IDeleteOrganization, IOrgActivityCount } from '@credebl/common/interfaces/organization.interface';
import { organisation, user } from '@prisma/client';
import { IOrgCredentials, IOrganizationInvitations, IOrganization, IOrganizationDashboard, IDeleteOrganization } from '@credebl/common/interfaces/organization.interface';
import { IAccessTokenData } from '@credebl/common/interfaces/interface';
import { IClientRoles } from '@credebl/client-registration/interfaces/client.interface';

Expand Down Expand Up @@ -208,6 +206,11 @@ export class OrganizationController {
return this.organizationService.getOrgDashboard(payload.orgId);
}

@MessagePattern({ cmd: 'get-organization-activity-count' })
async getOrganizationActivityCount(payload: { orgId: string; userId: string }): Promise<IOrgActivityCount> {
return this.organizationService.getOrganizationActivityCount(payload.orgId, payload.userId);
}

/**
* @returns organization profile details
*/
Expand Down
Loading

0 comments on commit 3d8e88f

Please sign in to comment.