From 9e37c01b2340875ea1943e95ead6da673dc38034 Mon Sep 17 00:00:00 2001 From: Nishad Shirsat <103021375+nishad-ayanworks@users.noreply.github.com> Date: Sat, 7 Oct 2023 19:25:46 +0530 Subject: [PATCH] feat: get endorsement transactions (#131) * worked on the GET API for endorsement transactions Signed-off-by: Nishad * Implemented type parameter in the GET API of endorser transactions Signed-off-by: Nishad --------- Signed-off-by: Nishad Signed-off-by: KulkarniShashank --- .../dtos/get-all-endorsements.dto.ts | 35 +++++++++++++++++ .../src/ecosystem/ecosystem.controller.ts | 38 +++++++++++++++++++ .../interfaces/endorsements.interface.ts | 9 +++++ libs/enum/src/enum.ts | 5 +++ .../prisma/data/credebl-master-table.json | 38 +++++++++++++++++++ .../migration.sql | 7 ++++ libs/prisma-service/prisma/schema.prisma | 22 +++++++---- 7 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 apps/api-gateway/src/ecosystem/dtos/get-all-endorsements.dto.ts create mode 100644 apps/ecosystem/interfaces/endorsements.interface.ts create mode 100644 libs/prisma-service/prisma/migrations/20231007125030_endorse_transaction_type_date/migration.sql diff --git a/apps/api-gateway/src/ecosystem/dtos/get-all-endorsements.dto.ts b/apps/api-gateway/src/ecosystem/dtos/get-all-endorsements.dto.ts new file mode 100644 index 000000000..a0878bf15 --- /dev/null +++ b/apps/api-gateway/src/ecosystem/dtos/get-all-endorsements.dto.ts @@ -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; + +} diff --git a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts index 8421faf9a..d28c9932b 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts @@ -91,6 +91,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 { + 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 }) diff --git a/apps/ecosystem/interfaces/endorsements.interface.ts b/apps/ecosystem/interfaces/endorsements.interface.ts new file mode 100644 index 000000000..d4c837c06 --- /dev/null +++ b/apps/ecosystem/interfaces/endorsements.interface.ts @@ -0,0 +1,9 @@ +export interface GetEndorsementsPayload { + ecosystemId: string; + orgId: string; + status: string; + pageNumber: number; + pageSize: number; + search: string; + type: string; + } \ No newline at end of file diff --git a/libs/enum/src/enum.ts b/libs/enum/src/enum.ts index 94ac465ea..e47471927 100644 --- a/libs/enum/src/enum.ts +++ b/libs/enum/src/enum.ts @@ -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 diff --git a/libs/prisma-service/prisma/data/credebl-master-table.json b/libs/prisma-service/prisma/data/credebl-master-table.json index a3966a6ca..5053c4d65 100644 --- a/libs/prisma-service/prisma/data/credebl-master-table.json +++ b/libs/prisma-service/prisma/data/credebl-master-table.json @@ -107,5 +107,43 @@ "registerDIDPayload": "", "indyNamespace": "indicio:testnet" } + ], + "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" + } ] } \ No newline at end of file diff --git a/libs/prisma-service/prisma/migrations/20231007125030_endorse_transaction_type_date/migration.sql b/libs/prisma-service/prisma/migrations/20231007125030_endorse_transaction_type_date/migration.sql new file mode 100644 index 000000000..472616297 --- /dev/null +++ b/libs/prisma-service/prisma/migrations/20231007125030_endorse_transaction_type_date/migration.sql @@ -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; diff --git a/libs/prisma-service/prisma/schema.prisma b/libs/prisma-service/prisma/schema.prisma index 5637e59d0..45aa68dd9 100644 --- a/libs/prisma-service/prisma/schema.prisma +++ b/libs/prisma-service/prisma/schema.prisma @@ -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]) }