Skip to content

Commit

Permalink
refactor: endorsement flow for key and web method (#831)
Browse files Browse the repository at this point in the history
* refactor: endorsement flow for key and web method

Signed-off-by: bhavanakarwade <[email protected]>

* refactor: send email for issuance

Signed-off-by: bhavanakarwade <[email protected]>

---------

Signed-off-by: bhavanakarwade <[email protected]>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 6, 2024
1 parent 2b8a8ef commit 4a8dfb2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
15 changes: 9 additions & 6 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,14 @@ export class AgentServiceService {
let agentProcess;
let ledgerIdData = [];
try {
if (payload.method !== DidMethod.KEY && payload.method !== DidMethod.WEB) {
let ledger;
const { network } = payload;
const ledger = await ledgerName(network);
if (network) {
ledger = await ledgerName(network);
} else {
ledger = Ledgers.Not_Applicable;
}

const ledgerList = (await this._getALlLedgerDetails()) as unknown as LedgerListResponse;
const isLedgerExist = ledgerList.response.find((existingLedgers) => existingLedgers.name === ledger);
if (!isLedgerExist) {
Expand All @@ -813,10 +818,8 @@ export class AgentServiceService {
description: ResponseMessages.errorMessages.notFound
});
}

ledgerIdData = await this.agentServiceRepository.getLedgerDetails(ledger);
}


const agentSpinUpStatus = AgentSpinUpStatus.PROCESSED;

// Create and stored agent details
Expand Down Expand Up @@ -859,7 +862,7 @@ export class AgentServiceService {
orgAgentTypeId,
tenantId: tenantDetails.walletResponseDetails['id'],
walletName: payload.label,
ledgerId: ledgerIdData ? ledgerIdData.map((item) => item.id) : null,
ledgerId: ledgerIdData.map((item) => item.id),
id: agentProcess?.id
};

Expand Down
5 changes: 3 additions & 2 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,11 @@ export class EcosystemController {
@Res() res: Response
): Promise<Response> {
const transactionResponse = await this.ecosystemService.submitTransaction(endorsementId, ecosystemId, orgId, user);

const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.ecosystem.success.submit,
data: transactionResponse
message: transactionResponse?.['responseMessage'],
data: transactionResponse?.['txnPayload']
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}
Expand Down
18 changes: 12 additions & 6 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EcosystemInviteTemplate } from '../templates/EcosystemInviteTemplate';
import { EmailDto } from '@credebl/common/dtos/email.dto';
import { sendEmail } from '@credebl/common/send-grid-helper-file';
import { AcceptRejectEcosystemInvitationDto } from '../dtos/accept-reject-ecosysteminvitation.dto';
import { EcosystemConfigSettings, Invitation, JSONSchemaType, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum';
import { EcosystemConfigSettings, Invitation, LedgerLessConstant, OrgAgentType, SchemaType, SchemaTypeEnum } from '@credebl/enum/enum';
import {
DeploymentModeType,
EcosystemOrgStatus,
Expand Down Expand Up @@ -136,7 +136,7 @@ export class EcosystemService {
throw new NotFoundException(ResponseMessages.ecosystem.error.orgDidNotExist);
}

const ecosystemLedgers = orgDetails.org_agents.map((agent) => agent.ledgers.id);
const ecosystemLedgers = orgDetails.org_agents.map((agent) => agent.ledgers?.id);

const createEcosystem = await this.ecosystemRepository.createNewEcosystem(createEcosystemDto, ecosystemLedgers);
if (!createEcosystem) {
Expand Down Expand Up @@ -1604,7 +1604,7 @@ export class EcosystemService {
return this.ecosystemRepository.updateTransactionStatus(endorsementId, endorsementTransactionStatus.SUBMITED);
}

async submitTransaction(transactionPayload: ITransactionData): Promise<object> {
async submitTransaction(transactionPayload: ITransactionData): Promise<{txnPayload: object, responseMessage: string}> {
try {
let txnPayload;

Expand All @@ -1624,13 +1624,19 @@ export class EcosystemService {
throw new ConflictException(ResponseMessages.ecosystem.error.transactionSubmitted);
}

const parsedRequestPayload = JSON.parse(endorsementPayload?.requestPayload);

const responseMessage = LedgerLessConstant.NO_LEDGER === parsedRequestPayload?.schemaType
? ResponseMessages.ecosystem.success.submitNoLedgerSchema
: ResponseMessages.ecosystem.success.submit;

if (endorsementPayload?.type === endorsementTransactionType.W3C_SCHEMA) {
txnPayload = await this.submitW3CTransaction(transactionPayload);
} else {
txnPayload = await this.submitIndyTransaction(transactionPayload);
}

return txnPayload;
return { txnPayload, responseMessage };
} catch (error) {
this.logger.error(`In submit transaction: ${JSON.stringify(error)}`);
if (error?.error) {
Expand Down Expand Up @@ -1773,11 +1779,11 @@ export class EcosystemService {
schemaPayload: {
schemaName: w3cEndorsementTransactionPayload?.requestBody?.['schemaName'],
attributes: w3cEndorsementTransactionPayload?.requestBody?.['attributes'],
schemaType: JSONSchemaType.POLYGON_W3C,
schemaType: w3cEndorsementTransactionPayload?.requestBody?.['schemaType'],
description: w3cEndorsementTransactionPayload?.requestBody?.['description']
}
},
orgId: transactionPayload?.orgId,
orgId: w3cEndorsementTransactionPayload?.['ecosystemOrgs']?.orgId,
user: transactionPayload?.user
};

Expand Down
5 changes: 2 additions & 3 deletions apps/issuance/src/issuance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { ICredentialOfferResponse, IDeletedIssuanceRecords, IIssuedCredential, I
import { OOBIssueCredentialDto } from 'apps/api-gateway/src/issuance/dtos/issuance.dto';
import { RecordType, agent_invitations, organisation, user } from '@prisma/client';
import { createOobJsonldIssuancePayload, validateEmail } from '@credebl/common/cast.helper';
// import { sendEmail } from '@credebl/common/send-grid-helper-file';
import { sendEmail } from '@credebl/common/send-grid-helper-file';
import * as pLimit from 'p-limit';
import { UserActivityRepository } from 'libs/user-activity/repositories';
import { validateW3CSchemaAttributes } from '../libs/helpers/attributes.validator';
Expand Down Expand Up @@ -805,8 +805,7 @@ async sendEmailForCredentialOffer(sendEmailCredentialOffer: SendEmailCredentialO
}
];

const isEmailSent = true; // change this after testing on local
// const isEmailSent = await sendEmail(this.emailData);
const isEmailSent = await sendEmail(this.emailData);

this.logger.log(`isEmailSent ::: ${JSON.stringify(isEmailSent)}-${this.counter}`);
this.counter++;
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export class SchemaService extends BaseService {
async createW3CSchema(orgId:string, schemaPayload: ICreateW3CSchema, user: string): Promise<ISchemaData> {
try {
let createSchema;

const { description, attributes, schemaName} = schemaPayload;
const agentDetails = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
if (!agentDetails) {
Expand Down

0 comments on commit 4a8dfb2

Please sign in to comment.