From 7820746c1de1b92ca2e0a6727b46464ea47d06a2 Mon Sep 17 00:00:00 2001 From: sanjay-k1910 Date: Wed, 31 Jan 2024 21:56:43 +0530 Subject: [PATCH] refactor: decline endorsement transaction API response Signed-off-by: sanjay-k1910 --- apps/api-gateway/src/ecosystem/ecosystem.controller.ts | 9 +++++---- apps/api-gateway/src/ecosystem/ecosystem.service.ts | 2 +- apps/ecosystem/src/ecosystem.repository.ts | 3 ++- apps/ecosystem/src/ecosystem.service.ts | 7 ++++++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts index 502bb5732..fae127e1b 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.controller.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.controller.ts @@ -528,12 +528,13 @@ export class EcosystemController { @Param('orgId') orgId: string, @Res() res: Response ): Promise { - await this.ecosystemService.declineEndorsementRequestByLead(ecosystemId, endorsementId, orgId); + const response = await this.ecosystemService.declineEndorsementRequestByLead(ecosystemId, endorsementId, orgId); const finalResponse: IResponse = { - statusCode: 200, - message: ResponseMessages.ecosystem.success.DeclineEndorsementTransaction + statusCode: HttpStatus.OK, + message: ResponseMessages.ecosystem.success.DeclineEndorsementTransaction, + data: response }; - return res.status(200).json(finalResponse); + return res.status(HttpStatus.OK).json(finalResponse); } diff --git a/apps/api-gateway/src/ecosystem/ecosystem.service.ts b/apps/api-gateway/src/ecosystem/ecosystem.service.ts index 04196f4ca..2494fee1b 100644 --- a/apps/api-gateway/src/ecosystem/ecosystem.service.ts +++ b/apps/api-gateway/src/ecosystem/ecosystem.service.ts @@ -190,6 +190,6 @@ export class EcosystemService extends BaseService { orgId: string ): Promise<{ response: object }> { const payload = { ecosystemId, endorsementId, orgId }; - return this.sendNats(this.serviceProxy, 'decline-endorsement-transaction', payload); + return this.sendNatsMessage(this.serviceProxy, 'decline-endorsement-transaction', payload); } } diff --git a/apps/ecosystem/src/ecosystem.repository.ts b/apps/ecosystem/src/ecosystem.repository.ts index b42159ae7..10395897d 100644 --- a/apps/ecosystem/src/ecosystem.repository.ts +++ b/apps/ecosystem/src/ecosystem.repository.ts @@ -1071,7 +1071,8 @@ async findEcosystemMembers( } } - async updateEndorsementRequestStatus(ecosystemId: string, endorsementId: string): Promise { + // eslint-disable-next-line camelcase + async updateEndorsementRequestStatus(ecosystemId: string, endorsementId: string): Promise { try { const endorsementTransaction = await this.prisma.endorsement_transaction.findUnique({ diff --git a/apps/ecosystem/src/ecosystem.service.ts b/apps/ecosystem/src/ecosystem.service.ts index 91765af85..56a01d51c 100644 --- a/apps/ecosystem/src/ecosystem.service.ts +++ b/apps/ecosystem/src/ecosystem.service.ts @@ -1465,7 +1465,12 @@ export class EcosystemService { async declineEndorsementRequestByLead(ecosystemId: string, endorsementId: string): Promise { try { - return await this.ecosystemRepository.updateEndorsementRequestStatus(ecosystemId, endorsementId); + const declineResponse = await this.ecosystemRepository.updateEndorsementRequestStatus(ecosystemId, endorsementId); + + // To return selective response + this.removeEndorsementTransactionFields(declineResponse); + + return declineResponse; } catch (error) { this.logger.error(`error in decline endorsement request: ${error}`); throw new RpcException(error.response ? error.response : error);