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

feat: get endorsement transactions #131

Merged
merged 3 commits into from
Oct 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
35 changes: 35 additions & 0 deletions apps/api-gateway/src/ecosystem/dtos/get-all-endorsements.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import { Transform, Type } from 'class-transformer';
import { toNumber } from '@credebl/common/cast.helper';

import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsOptional, IsString } from 'class-validator';
import { EndorserTransactionType } from '@credebl/enum/enum';

export class GetAllEndorsementsDto {
@ApiProperty({ required: false, default: 1 })
@IsOptional()
@Type(() => Number)
@Transform(({ value }) => toNumber(value))
pageNumber = 1;

@ApiProperty({ required: false })
@IsOptional()
@IsString()
@Type(() => String)
search = '';

@ApiProperty({ required: false })
@IsOptional()
@Type(() => Number)
@Transform(({ value }) => toNumber(value))
pageSize = 10;

@ApiProperty({
enum: [EndorserTransactionType.SCHEMA, EndorserTransactionType.CREDENTIAL_DEFINITION]
})
@IsOptional()
@IsEnum(EndorserTransactionType)
type: EndorserTransactionType.SCHEMA | EndorserTransactionType.CREDENTIAL_DEFINITION;

}
39 changes: 39 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { EcosystemRolesGuard } from '../authz/guards/ecosystem-roles.guard';
import { EcosystemsRoles, Roles } from '../authz/decorators/roles.decorator';
import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { OrgRoles } from 'libs/org-roles/enums';
import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto';
import { CreateEcosystemDto } from './dtos/create-ecosystem-dto';


Expand Down Expand Up @@ -104,6 +105,44 @@ export class EcosystemController {

}

@Get('/:ecosystemId/:orgId/endorsement-transactions')
@ApiOperation({ summary: 'Get all endorsement transactions', description: 'Get all endorsement transactions' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'), EcosystemRolesGuard, OrgRolesGuard)
@ApiBearerAuth()
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_OWNER, EcosystemRoles.ECOSYSTEM_LEAD, EcosystemRoles.ECOSYSTEM_MEMBER)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER)
@ApiQuery({
name: 'pageNumber',
type: Number,
required: false
})
@ApiQuery({
name: 'pageSize',
type: Number,
required: false
})
@ApiQuery({
name: 'search',
type: String,
required: false
})
async getEndorsementTranasactions(
@Param('ecosystemId') ecosystemId: string,
@Param('orgId') orgId: string,
@Query() getAllEndorsementsDto: GetAllEndorsementsDto,
@Res() res: Response
): Promise<Response> {
const ecosystemList = await this.ecosystemService.getEndorsementTranasactions(ecosystemId, orgId, getAllEndorsementsDto);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: `Endorser transactions fetched successfully`,
data: ecosystemList.response
};
return res.status(HttpStatus.OK).json(finalResponse);
}


@Get('/:ecosystemId/:orgId/invitations')
@ApiOperation({ summary: 'Get all sent invitations', description: 'Get all sent invitations' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
Expand Down
11 changes: 11 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BulkEcosystemInvitationDto } from './dtos/send-invitation.dto';
import { AcceptRejectEcosystemInvitationDto } from './dtos/accept-reject-ecosysteminvitation-dto';
import { GetAllEcosystemInvitationsDto } from './dtos/get-all-sent-invitations.dto';
import { GetAllSentEcosystemInvitationsDto } from './dtos/get-all-sent-ecosystemInvitations-dto';
import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto';
import { RequestSchemaDto } from './dtos/request-schema-dto';


Expand Down Expand Up @@ -99,6 +100,16 @@ export class EcosystemService extends BaseService {
return this.sendNats(this.serviceProxy, 'fetch-ecosystem-org-data', payload);
}

async getEndorsementTranasactions(
ecosystemId: string,
orgId: string,
getAllEndorsements: GetAllEndorsementsDto
): Promise<{ response: object }> {
const { pageNumber, pageSize, search, type } = getAllEndorsements;
const payload = { ecosystemId, orgId, pageNumber, pageSize, search, type };
return this.sendNats(this.serviceProxy, 'get-endorsement-transactions', payload);
}


async schemaEndorsementRequest(requestSchemaPayload: RequestSchemaDto, orgId: number): Promise<object> {
const payload = { requestSchemaPayload, orgId};
Expand Down
9 changes: 9 additions & 0 deletions apps/ecosystem/interfaces/endorsements.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface GetEndorsementsPayload {
ecosystemId: string;
orgId: string;
status: string;
pageNumber: number;
pageSize: number;
search: string;
type: string;
}
12 changes: 7 additions & 5 deletions apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Body } from '@nestjs/common';
import { BulkSendInvitationDto } from '../dtos/send-invitation.dto';
import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosysteminvitation.dto';
import { FetchInvitationsPayload } from '../interfaces/invitations.interface';
import { GetEndorsementsPayload } from '../interfaces/endorsements.interface';
import { RequestSchemaEndorsement } from '../interfaces/ecosystem.interfaces';

@Controller()
Expand Down Expand Up @@ -97,14 +98,15 @@ export class EcosystemController {
);
}

@MessagePattern({ cmd: 'fetch-ecosystem-org-data' })
async fetchEcosystemOrg(
@Body() payload: { ecosystemId: string, orgId: string}
@MessagePattern({ cmd: 'get-endorsement-transactions' })
async getEndorsementTransactions(
@Body() payload: GetEndorsementsPayload
): Promise<object> {
return this.ecosystemService.fetchEcosystemOrg(
return this.ecosystemService.getEndorsementTransactions(
payload
);
}
}


/**
*
Expand Down
45 changes: 43 additions & 2 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,48 @@ export class EcosystemRepository {

}

/**
async getEndorsementsWithPagination(queryObject: object, pageNumber: number, pageSize: number): Promise<object> {
try {
const result = await this.prisma.$transaction([
this.prisma.endorsement_transaction.findMany({
where: {
...queryObject
},
select:{
id:true,
endorserDid: true,
authorDid: true,
status: true,
type: true,
ecosystemOrgs: true
},
take: pageSize,
skip: (pageNumber - 1) * pageSize,
orderBy: {
createDateTime: 'desc'
}
}),
this.prisma.endorsement_transaction.count({
where: {
...queryObject
}
})
]);

// eslint-disable-next-line prefer-destructuring
const transactions = result[0];
// eslint-disable-next-line prefer-destructuring
const totalCount = result[1];
const totalPages = Math.ceil(totalCount / pageSize);

return { totalPages, transactions };
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}

/**
* Description: Get getAgentEndPoint by orgId
* @param orgId
* @returns Get getAgentEndPoint details
Expand Down Expand Up @@ -419,6 +460,7 @@ export class EcosystemRepository {
throw new InternalServerErrorException(error);
}
}

// eslint-disable-next-line camelcase
async getEcosystemOrgDetailsbyId(orgId: string): Promise<ecosystem_orgs> {
try {
Expand Down Expand Up @@ -481,5 +523,4 @@ export class EcosystemRepository {
}
}


}
28 changes: 27 additions & 1 deletion apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosys
import { Invitation, OrgAgentType } from '@credebl/enum/enum';
import { EcosystemOrgStatus, EcosystemRoles } from '../enums/ecosystem.enum';
import { FetchInvitationsPayload } from '../interfaces/invitations.interface';
import { GetEndorsementsPayload } from '../interfaces/endorsements.interface';
import { RequestSchemaEndorsement, SchemaMessage, SchemaTransactionPayload, SchemaTransactionResponse, SignedTransactionMessage } from '../interfaces/ecosystem.interfaces';
// eslint-disable-next-line camelcase
import { platform_config } from '@prisma/client';
Expand Down Expand Up @@ -293,7 +294,7 @@ export class EcosystemService {
endorserDid: ecosystemLeadAgentDetails.orgDid,
authorDid: agentDetails.orgDid,
requestPayload: schemaTransactionRequest.message.schemaState.schemaRequest,
status: "Requested",
status: 'Requested',
ecosystemOrgId: getEcosystemOrgDetailsByOrgId.id
};
return this.ecosystemRepository.storeTransactionRequest(schemaTransactionResponse);
Expand Down Expand Up @@ -446,5 +447,30 @@ export class EcosystemService {
return platformConfigData[0].enableEcosystem;
}

async getEndorsementTransactions(payload: GetEndorsementsPayload): Promise<object> {
const {ecosystemId, orgId, pageNumber, pageSize, search, type } = payload;
try {

const query = {
ecosystemOrgs: {
ecosystemId,
orgId
},
OR: [
{ status: { contains: search, mode: 'insensitive' } },
{ authorDid: { contains: search, mode: 'insensitive' } }
]
};

if (type) {
query['type'] = type;
}

return await this.ecosystemRepository.getEndorsementsWithPagination(query, pageNumber, pageSize);
} catch (error) {
this.logger.error(`In error getEndorsementTransactions: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}

}
5 changes: 5 additions & 0 deletions libs/enum/src/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export enum EcosystemRoles {
ECOSYSTEM_OWNER = 'Ecosystem Owner'
}

export enum EndorserTransactionType{
SCHEMA = 'schema',
CREDENTIAL_DEFINITION = 'credential-definition',
}

export enum OrgAgentType {
DEDICATED = 1,
SHARED = 2
Expand Down
38 changes: 38 additions & 0 deletions libs/prisma-service/prisma/data/credebl-master-table.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,43 @@
"registerDIDPayload": "",
"indyNamespace": "indicio:testnet"
}
],
tipusinghaw marked this conversation as resolved.
Show resolved Hide resolved
"endorseData": [
{
"id": "0f8fad5b-d9cb-469f-a165-70867728950f",
"endorserDid": "endorser123",
"authorDid": "author456",
"requestPayload": "{\"type\": \"dummy_request_1\"}",
"responsePayload": "{\"type\": \"dummy_response_1\"}",
"status": "Requested",
"ecosystemOrgId": "1c247b4a-e2f6-48c0-8aa2-65ea47474294"
},
{
"id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
"endorserDid": "endorser789",
"authorDid": "author101",
"requestPayload": "{\"type\": \"dummy_request_2\"}",
"responsePayload": "{\"type\": \"dummy_response_2\"}",
"status": "Signed",
"ecosystemOrgId": "1c247b4a-e2f6-48c0-8aa2-65ea47474294"
},
{
"id": "a89b6e81-a1ff-4d13-a9e2-17176e707aac",
"endorserDid": "endorser321",
"authorDid": "author654",
"requestPayload": "{\"type\": \"dummy_request_3\"}",
"responsePayload": "{\"type\": \"dummy_response_3\"}",
"status": "Declined",
"ecosystemOrgId": "a2443e09-45be-4739-b8b3-0d4ffaecea94"
},
{
"id": "f47ac10b-58cc-4372-a567-0e02b2c3d47c",
"endorserDid": "endorser999",
"authorDid": "author777",
"requestPayload": "{\"type\": \"dummy_request_4\"}",
"responsePayload": "{\"type\": \"dummy_response_4\"}",
"status": "Submitted",
"ecosystemOrgId": "ca6ee687-a3a9-42ce-9e49-02bf62f5c93a"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- AlterTable
ALTER TABLE "endorsement_transaction" ADD COLUMN "createDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "createdBy" INTEGER NOT NULL DEFAULT 1,
ADD COLUMN "deletedAt" TIMESTAMP(6),
ADD COLUMN "lastChangedBy" INTEGER NOT NULL DEFAULT 1,
ADD COLUMN "lastChangedDateTime" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
ADD COLUMN "type" TEXT;
22 changes: 14 additions & 8 deletions libs/prisma-service/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,18 @@ model ecosystem_orgs {
}

model endorsement_transaction {
id String @id @default(uuid())
endorserDid String
authorDid String
requestPayload String
responsePayload String
status String
ecosystemOrgId String
ecosystemOrgs ecosystem_orgs @relation(fields: [ecosystemOrgId], references: [id])
id String @id @default(uuid())
endorserDid String
authorDid String
requestPayload String
responsePayload String
type String?
createDateTime DateTime @default(now()) @db.Timestamptz(6)
createdBy Int @default(1)
lastChangedDateTime DateTime @default(now()) @db.Timestamptz(6)
lastChangedBy Int @default(1)
deletedAt DateTime? @db.Timestamp(6)
status String
ecosystemOrgId String
ecosystemOrgs ecosystem_orgs @relation(fields: [ecosystemOrgId], references: [id])
}