Skip to content

Commit

Permalink
refactor: removed org validation for reject
Browse files Browse the repository at this point in the history
Signed-off-by: tipusinghaw <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
tipusinghaw authored and KulkarniShashank committed Sep 11, 2024
1 parent 809f3f6 commit 05b8534
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 3 deletions.
171 changes: 170 additions & 1 deletion apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,5 +564,174 @@ export class EcosystemRepository {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
}
}
});
return ecosystemLeadDetails;

} catch (error) {
this.logger.error(`Error in getting ecosystem lead details for the ecosystem: ${error.message} `);
throw error;
}
}
// eslint-disable-next-line camelcase
async getEndorsementTransactionById(endorsementId: string, status: endorsementTransactionStatus): Promise<endorsement_transaction> {
try {
const ecosystemLeadDetails = await this.prisma.endorsement_transaction.findFirst({
where: {
id: endorsementId,
status
},
include: {
ecosystemOrgs: {
select: {
orgId: true
}
}
}
});

return ecosystemLeadDetails;

} catch (error) {
this.logger.error(`Error in getting ecosystem lead details for the ecosystem: ${error.message} `);
throw error;
}
}

async updateTransactionDetails(
endorsementId: string,
schemaTransactionRequest: string

// eslint-disable-next-line camelcase,
): Promise<object> {
try {
const updatedTransaction = await this.prisma.endorsement_transaction.update({
where: { id: endorsementId },
data: {
responsePayload: schemaTransactionRequest,
status: endorsementTransactionStatus.SIGNED
}
});

return updatedTransaction;

} catch (error) {
this.logger.error(`Error in updating endorsement transaction: ${error.message}`);
throw error;
}
}

async updateTransactionStatus(
endorsementId: string,
status: endorsementTransactionStatus
// eslint-disable-next-line camelcase,
): Promise<object> {
try {
const updatedTransaction = await this.prisma.endorsement_transaction.update({
where: { id: endorsementId },
data: {
status
}
});

return updatedTransaction;

} catch (error) {
this.logger.error(`Error in updating endorsement transaction: ${error.message}`);
throw error;
}
}

async saveSchema(schemaResult: SaveSchema): Promise<schema> {
try {
const { name, version, attributes, schemaLedgerId, issuerId, createdBy, lastChangedBy, publisherDid, orgId, ledgerId } = schemaResult;
const saveResult = await this.prisma.schema.create({
data: {
name,
version,
attributes,
schemaLedgerId,
issuerId,
createdBy: Number(createdBy),
lastChangedBy: Number(lastChangedBy),
publisherDid,
orgId: Number(orgId),
ledgerId
}
});
return saveResult;
} catch (error) {
this.logger.error(`Error in storing schema for submit transaction: ${error.message} `);
throw error;
}
}

// eslint-disable-next-line camelcase
async saveCredDef(credDefResult: saveCredDef): Promise<credential_definition> {
try {
const { schemaLedgerId, tag, credentialDefinitionId, revocable, createdBy, orgId, schemaId } = credDefResult;
const saveResult = await this.prisma.credential_definition.create({
data: {
schemaLedgerId,
tag,
credentialDefinitionId,
revocable,
createdBy: Number(createdBy),
orgId: Number(orgId),
schemaId
}
});
return saveResult;
} catch (error) {
this.logger.error(`Error in saving credential-definition for submit transaction: ${error.message} `);
throw error;
}
}

async getSchemaDetailsById(schemaLedgerId: string): Promise<schema | null> {
try {
const schemaDetails = await this.prisma.schema.findFirst({
where: {
schemaLedgerId
}
});
return schemaDetails;
} catch (error) {
this.logger.error(`Error in fetching schema details for submit transaction: ${error.message}`);
throw error;
}
}

async updateEndorsementRequestStatus(ecosystemId: 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.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;
}
}
}
4 changes: 2 additions & 2 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,10 +671,10 @@ export class EcosystemService {
* @returns EndorsementTransactionRequest Status message
*/

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

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

0 comments on commit 05b8534

Please sign in to comment.