Skip to content

Commit

Permalink
refactor: Implemented auto flag handling within the ecosystem and int…
Browse files Browse the repository at this point in the history
…roduced validation. (#158)

* Added the auto submit flag for automatic submit the transaction

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Removed unnecessary params

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Error handling in the schema endorsement

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* feat: Schema and credDef auto sign and submit transaction

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Solved issue when schema sign

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Added the validation for the cedDef create and write

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* feat: auto endorsement flag handle and refactor schema and cred-def

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Solved conflicts in endorsement service

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Change the API URL for auto sign and submit flag

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

* Modify the error messages in ecosystem

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>

---------

Signed-off-by: KulkarniShashank <shashank.kulkarni@ayanworks.com>
  • Loading branch information
KulkarniShashank authored and KulkarniShashank committed Sep 11, 2024
1 parent 5c7ae15 commit a784687
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 148 deletions.
13 changes: 8 additions & 5 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export class AgentServiceService {
socket.emit('agent-spinup-process-initiated', { clientId: agentSpinupDto.clientSocketId });
}

await this._agentSpinup(walletProvisionPayload, agentSpinupDto, orgApiKey, orgData, user, socket);
await this._agentSpinup(walletProvisionPayload, agentSpinupDto, orgApiKey, orgData, user, socket, agentSpinupDto.ledgerId);
const agentStatusResponse = {
agentSpinupStatus: 1
};
Expand All @@ -251,7 +251,7 @@ export class AgentServiceService {
}
}

async _agentSpinup(walletProvisionPayload: IWalletProvision, agentSpinupDto: IAgentSpinupDto, orgApiKey: string, orgData: organisation, user: IUserRequestInterface, socket): Promise<void> {
async _agentSpinup(walletProvisionPayload: IWalletProvision, agentSpinupDto: IAgentSpinupDto, orgApiKey: string, orgData: organisation, user: IUserRequestInterface, socket, ledgerId: number[]): Promise<void> {
try {
const agentSpinUpResponse = new Promise(async (resolve, _reject) => {

Expand Down Expand Up @@ -288,7 +288,8 @@ export class AgentServiceService {
agentsTypeId: AgentType.AFJ,
orgId: orgData.id,
walletName: agentSpinupDto.walletName,
clientSocketId: agentSpinupDto.clientSocketId
clientSocketId: agentSpinupDto.clientSocketId,
ledgerId
};

if (agentEndPoint && agentSpinupDto.clientSocketId) {
Expand Down Expand Up @@ -358,7 +359,8 @@ export class AgentServiceService {
orgId: payload.orgId,
agentEndPoint: payload.agentEndPoint,
agentId: payload.agentId,
orgAgentTypeId: OrgAgentType.DEDICATED
orgAgentTypeId: OrgAgentType.DEDICATED,
ledgerId: payload.ledgerId
};


Expand Down Expand Up @@ -543,7 +545,8 @@ export class AgentServiceService {
agentEndPoint: platformAdminSpinnedUp.org_agents[0].agentEndPoint,
orgAgentTypeId: OrgAgentType.SHARED,
tenantId: tenantDetails.tenantRecord.id,
walletName: label
walletName: label,
ledgerId: payload.ledgerId
};

if (payload.clientSocketId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export interface IStoreOrgAgentDetails {
agentId?: number;
orgAgentTypeId?: OrgAgentType;
tenantId?: string;
ledgerId?: number[];
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class AgentServiceRepository {
agentId: storeOrgAgentDetails.agentId ? storeOrgAgentDetails.agentId : null,
orgAgentTypeId: storeOrgAgentDetails.orgAgentTypeId ? storeOrgAgentDetails.orgAgentTypeId : null,
tenantId: storeOrgAgentDetails.tenantId ? storeOrgAgentDetails.tenantId : null,
ledgerId: 1
ledgerId: storeOrgAgentDetails.ledgerId[0]
}
});
} catch (error) {
Expand Down
91 changes: 42 additions & 49 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ export class EcosystemController {
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_OWNER, EcosystemRoles.ECOSYSTEM_LEAD, EcosystemRoles.ECOSYSTEM_MEMBER)
@ApiBearerAuth()

async getEcosystemDashboardDetails(@Param('ecosystemId') ecosystemId: string, @Param('orgId') orgId: string, @Res() res: Response): Promise<Response> {

const getEcosystemDetails = await this.ecosystemService.getEcosystemDashboardDetails(ecosystemId, orgId);
Expand Down Expand Up @@ -189,49 +188,9 @@ export class EcosystemController {
}


/**
*
* @param orgId
* @param res
* @returns Ecosystem members list
*/
@Get('/:ecosystemId/:orgId/members')
// @Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
// @EcosystemsRoles(EcosystemRoles.ECOSYSTEM_OWNER, EcosystemRoles.ECOSYSTEM_LEAD, EcosystemRoles.ECOSYSTEM_MEMBER)
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@ApiOperation({ summary: 'Get ecosystem members list', description: 'Get ecosystem members list.' })
@ApiQuery({
name: 'pageNumber',
type: Number,
required: false
})
@ApiQuery({
name: 'pageSize',
type: Number,
required: false
})
@ApiQuery({
name: 'search',
type: String,
required: false
})
async getEcosystemMembers(
@Param('ecosystemId') ecosystemId: string,
@Param('orgId') orgId: string,
@Query() getEcosystemMembers: GetAllEcosystemMembersDto,
@Res() res: Response): Promise<Response> {
const members = await this.ecosystemService.getEcosystemMembers(ecosystemId, getEcosystemMembers);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.ecosystem.success.fetchMembers,
data: members?.response
};

return res.status(HttpStatus.OK).json(finalResponse);
}

return res.status(HttpStatus.OK).json(finalResponse);
}

/**
*
* @param createOrgDto
Expand Down Expand Up @@ -297,7 +256,7 @@ export class EcosystemController {
@ApiBearerAuth()
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_LEAD)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
async SignEndorsementRequests(@Param('endorsementId') endorsementId: string, @Param('ecosystemId') ecosystemId: string, @Param('orgId') orgId: number, @Res() res: Response): Promise<Response> {
async SignEndorsementRequests(@Param('endorsementId') endorsementId: string, @Param('ecosystemId') ecosystemId: string, @Param('orgId') orgId: number, @Res() res: Response): Promise<Response> {
await this.ecosystemService.signTransaction(endorsementId, ecosystemId);
const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
Expand Down Expand Up @@ -356,10 +315,44 @@ export class EcosystemController {

}

@Get('/:ecosystemId/invitations')
@ApiOperation({ summary: 'Get all sent invitations', description: 'Get all sent invitations' })
@ApiResponse({ status: 200, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'))
/**
*
* @param res
* @returns
*/
@Put('transaction/endorsement/auto')
@ApiOperation({
summary: 'Auto sign and submit transactions',
description: 'Auto sign and submit transactions'
})
@UseGuards(AuthGuard('jwt'), EcosystemRolesGuard, OrgRolesGuard)
@ApiBearerAuth()
@EcosystemsRoles(EcosystemRoles.ECOSYSTEM_LEAD)
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
async autoSignAndSubmitTransaction(
@Res() res: Response
): Promise<object> {
await this.ecosystemService.autoSignAndSubmitTransaction();
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.ecosystem.success.AutoEndorsementTransaction
};
return res.status(HttpStatus.OK).json(finalResponse);
}

/**
*
* @param acceptRejectEcosystemInvitation
* @param reqUser
* @param res
* @returns Ecosystem invitation status
*/
@Put('/:orgId/invitations/:invitationId')
@ApiOperation({
summary: 'Accept or reject ecosystem invitation',
description: 'Accept or Reject ecosystem invitations'
})
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiBearerAuth()
@ApiQuery({
name: 'pageNumber',
Expand Down
95 changes: 89 additions & 6 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class EcosystemService extends BaseService {
const payload = { orgId };
return this.sendNats(this.serviceProxy, 'get-all-ecosystem', payload);
}

/**
*
*
Expand All @@ -63,8 +63,8 @@ export class EcosystemService extends BaseService {
* @returns
*/
async createInvitation(bulkInvitationDto: BulkEcosystemInvitationDto, userId: string): Promise<object> {
const payload = { bulkInvitationDto, userId };
return this.sendNats(this.serviceProxy, 'send-ecosystem-invitation', payload);
const payload = { bulkInvitationDto, userId };
return this.sendNats(this.serviceProxy, 'send-ecosystem-invitation', payload);
}

async getInvitationsByEcosystemId(
Expand All @@ -76,8 +76,8 @@ export class EcosystemService extends BaseService {
const payload = { ecosystemId, pageNumber, pageSize, search, userId };
return this.sendNats(this.serviceProxy, 'get-sent-invitations-ecosystemId', payload);
}
/**

/**
*
* @returns Ecosystem members
*/
Expand All @@ -88,6 +88,89 @@ export class EcosystemService extends BaseService {
const { pageNumber, pageSize, search } = getEcosystemMembers;
const payload = { ecosystemId, pageNumber, pageSize, search};
return this.sendNats(this.serviceProxy, 'fetch-ecosystem-members', payload);
}
}

/**
*
* @returns Ecosystem Invitations details
*/
async getEcosystemInvitations(
getAllInvitationsDto: GetAllSentEcosystemInvitationsDto,
userEmail: string,
status: string
): Promise<{ response: object }> {
const { pageNumber, pageSize, search } = getAllInvitationsDto;
const payload = { userEmail, status, pageNumber, pageSize, search };
return this.sendNats(this.serviceProxy, 'get-ecosystem-invitations', payload);
}


async deleteEcosystemInvitations(
invitationId: string
): Promise<object> {
const payload = { invitationId };
return this.sendNats(this.serviceProxy, 'delete-ecosystem-invitations', payload);
}
async acceptRejectEcosystemInvitaion(
acceptRejectInvitation: AcceptRejectEcosystemInvitationDto,
userEmail: string
): Promise<{ response: string }> {
const payload = { acceptRejectInvitation, userEmail };
return this.sendNats(this.serviceProxy, 'accept-reject-ecosystem-invitations', payload);
}


async fetchEcosystemOrg(
ecosystemId: string,
orgId: string
): Promise<{ response: object }> {
const payload = { ecosystemId, orgId };
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, ecosystemId: string): Promise<object> {
const payload = { requestSchemaPayload, orgId, ecosystemId };
return this.sendNats(this.serviceProxy, 'schema-endorsement-request', payload);
}

async credDefEndorsementRequest(requestCredDefPayload: RequestCredDefDto, orgId: number, ecosystemId: string): Promise<object> {
const payload = { requestCredDefPayload, orgId, ecosystemId };
return this.sendNats(this.serviceProxy, 'credDef-endorsement-request', payload);
}

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

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

async autoSignAndSubmitTransaction(): Promise<{ response: object }> {
const payload = {};
return this.sendNats(this.serviceProxy, 'auto-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);
}

}
Loading

0 comments on commit a784687

Please sign in to comment.