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:Decline endorsement request by lead #145

Merged
merged 6 commits into from
Oct 12, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class DeclienEndorsementTransactionDto {
ecosystemId: string;
orgId: string;
endorsementId: string;

}
34 changes: 34 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { GetAllEcosystemMembersDto } from './dtos/get-members.dto';
import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto';
import { CreateEcosystemDto } from './dtos/create-ecosystem-dto';


@UseFilters(CustomExceptionFilter)
@Controller('ecosystem')
@ApiTags('ecosystem')
Expand Down Expand Up @@ -396,6 +397,7 @@ export class EcosystemController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}


@Put('/:ecosystemId/:orgId')
@ApiOperation({ summary: 'Edit ecosystem', description: 'Edit existing ecosystem' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
Expand All @@ -416,6 +418,37 @@ export class EcosystemController {
return res.status(HttpStatus.OK).json(finalResponse);
}


/**
*
* @param declineEndorsementTransactionRequest
*
* @param res
* @returns endorsement transaction status
*/
@Put('/:ecosystemId/:orgId/transactions/:endorsementId')
@ApiOperation({
summary: 'Decline Endorsement Request By Lead',
description: 'Decline Endorsement Request By Lead'
})
@UseGuards(AuthGuard('jwt'), EcosystemRolesGuard, OrgRolesGuard)
@ApiBearerAuth()
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_LEAD)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
async declineEndorsementRequestByLead(
@Param('ecosystemId') ecosystemId: string,
@Param('orgId') orgId: string,
@Param('endorsementId') endorsementId: string,
@Res() res: Response
): Promise<object> {
await this.ecosystemService.declineEndorsementRequestByLead(ecosystemId, orgId, endorsementId);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.ecosystem.success.DeclineEndorsementTransaction
};
return res.status(HttpStatus.OK).json(finalResponse);
}


@Delete('/:ecosystemId/:orgId/invitations/:invitationId')
@ApiOperation({ summary: 'Delete ecosystem pending invitations', description: 'Delete ecosystem pending invitations' })
Expand All @@ -438,4 +471,5 @@ export class EcosystemController {
return res.status(HttpStatus.OK).json(finalResponse);
}


}
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 @@ -8,6 +8,7 @@ import { GetAllEcosystemInvitationsDto } from './dtos/get-all-sent-invitations.d
import { GetAllSentEcosystemInvitationsDto } from './dtos/get-all-received-invitations.dto';
import { GetAllEcosystemMembersDto } from './dtos/get-members.dto';
import { GetAllEndorsementsDto } from './dtos/get-all-endorsements.dto';

import { RequestSchemaDto, RequestCredDefDto } from './dtos/request-schema.dto';

@Injectable()
Expand Down Expand Up @@ -159,4 +160,14 @@ export class EcosystemService extends BaseService {
const payload = { endorsementId, ecosystemId };
return this.sendNats(this.serviceProxy, 'sumbit-endorsement-transaction', payload);
}

async declineEndorsementRequestByLead(
ecosystemId: string,
endorsementId: string,
orgId: string
): Promise<{ response: object }> {
const payload = { ecosystemId, endorsementId, orgId };
return this.sendNats(this.serviceProxy, 'decline-endorsement-transaction', payload);
}

}
15 changes: 15 additions & 0 deletions apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,19 @@ export class EcosystemController {
): Promise<object> {
return this.ecosystemService.submitTransaction(payload.endorsementId, payload.ecosystemId);
}


/**
*
* @param payload
* @returns Declien Endorsement Transaction status
*/
@MessagePattern({ cmd: 'decline-endorsement-transaction' })
async declineEndorsementRequestByLead(payload: {
ecosystemId:string, endorsementId:string, orgId:string
}): Promise<object> {
return this.ecosystemService.declineEndorsementRequestByLead(payload.ecosystemId, payload.orgId, payload.endorsementId);
}


}
37 changes: 36 additions & 1 deletion apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { EcosystemInvitationStatus, EcosystemOrgStatus, EcosystemRoles, endorsem
import { updateEcosystemOrgsDto } from '../dtos/update-ecosystemOrgs.dto';
import { SchemaTransactionResponse } from '../interfaces/ecosystem.interfaces';
import { ResponseMessages } from '@credebl/common/response-messages';
import { NotFoundException } from '@nestjs/common';
// eslint-disable-next-line camelcase

@Injectable()
Expand Down Expand Up @@ -704,4 +705,38 @@ export class EcosystemRepository {
}
}

}
async updateEndorsementRequestStatus(ecosystemId: string, orgId: string, endorsementId: string): Promise<object> {
try {

const endorsementTransaction = await this.prisma.endorsement_transaction.findUnique({
where: { id: endorsementId, status: endorsementTransactionStatus.REQUESTED }
});

if (!endorsementTransaction) {
throw new NotFoundException(ResponseMessages.ecosystem.error.EndorsementTransactionNotFoundException);
}
const { ecosystemOrgId } = endorsementTransaction;

const endorsementTransactionEcosystemOrg = await this.prisma.ecosystem_orgs.findUnique({
where: { id: ecosystemOrgId }
});

if (endorsementTransactionEcosystemOrg.orgId === orgId && endorsementTransactionEcosystemOrg.ecosystemId === ecosystemId) {
const updatedEndorsementTransaction = await this.prisma.endorsement_transaction.update({
where: { id: endorsementId },
data: {
status: endorsementTransactionStatus.DECLINED
}
});

return updatedEndorsementTransaction;
} else {
throw new NotFoundException(ResponseMessages.ecosystem.error.OrgOrEcosystemNotFoundExceptionForEndorsementTransaction);
}
} catch (error) {
this.logger.error(`Error in updating endorsement transaction status: ${error.message}`);
throw error;
}
}
}

20 changes: 20 additions & 0 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { GetEndorsementsPayload } from '../interfaces/endorsements.interface';
import { platform_config } from '@prisma/client';
import { CommonConstants } from '@credebl/common/common.constant';


@Injectable()
export class EcosystemService {
constructor(
Expand Down Expand Up @@ -706,4 +707,23 @@ export class EcosystemService {
}
}


/**
*
* @param ecosystemId
* @param endorsementId
* @param orgId
* @returns EndorsementTransactionRequest Status message
*/

async declineEndorsementRequestByLead(ecosystemId:string, endorsementId:string, orgId:string): Promise<object> {
try {

return await this.ecosystemRepository.updateEndorsementRequestStatus(ecosystemId, orgId, endorsementId);
} catch (error) {
this.logger.error(`error in decline endorsement request: ${error}`);
throw new InternalServerErrorException(error);
}
}

}
9 changes: 6 additions & 3 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,9 @@ export const ResponseMessages = {
sign: 'Transaction request signed successfully',
invitationReject: 'Ecosystem invitation rejected',
invitationAccept: 'Ecosystem invitation accepted successfully',
fetchMembers: 'Ecosystem members fetched successfully',
fetchEndorsors: 'Endorser transactions fetched successfully'
fetchEndorsors: 'Endorser transactions fetched successfully',
DeclineEndorsementTransaction:'Decline endorsement request successfully',
fetchMembers: 'Ecosystem members fetched successfully'
},
error: {
notCreated: 'Error while creating ecosystem',
Expand All @@ -214,7 +215,9 @@ export const ResponseMessages = {
invalidOrgId: 'Invalid organization Id',
invalidEcosystemId: 'Invalid ecosystem Id',
invalidTransaction: 'Transaction does not exist',
invalidAgentUrl: 'Invalid agent url'
invalidAgentUrl: 'Invalid agent url',
EndorsementTransactionNotFoundException:'Endorsement transaction with status requested not found',
OrgOrEcosystemNotFoundExceptionForEndorsementTransaction:'Cannot update endorsement transaction status as OrgId and EcosystemId is not present in ecosystemOrg'
}
}
};