Skip to content

Commit

Permalink
fix: delete organization bugs (#829)
Browse files Browse the repository at this point in the history
* fix: send email verification issue

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

* refcator: schema endorsement flow

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

* fix: resolved sonar lint issues

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

* fix: worked on sonarcloud issues

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

* fix: delete organization bugs

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

---------

Signed-off-by: bhavanakarwade <[email protected]>
  • Loading branch information
bhavanakarwade authored Jul 8, 2024
1 parent 56fbe62 commit a6301b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
10 changes: 7 additions & 3 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import {
IAgentConfigure,
OrgDid
} from './interface/agent-service.interface';
import { AgentSpinUpStatus, AgentType, DidMethod, Ledgers, OrgAgentType } from '@credebl/enum/enum';
import { AgentSpinUpStatus, AgentType, DidMethod, Ledgers, OrgAgentType, PromiseResult } from '@credebl/enum/enum';
import { AgentServiceRepository } from './repositories/agent-service.repository';
import { Prisma, RecordType, ledgers, org_agents, organisation, platform_config, user } from '@prisma/client';
import { CommonConstants } from '@credebl/common/common.constant';
Expand Down Expand Up @@ -1659,11 +1659,15 @@ export class AgentServiceService {
this.agentServiceRepository.getAgentApiKey(orgId)
]);

if (getApiKeyResult.status === 'rejected') {
if (orgAgentResult.status === PromiseResult.FULFILLED && !orgAgentResult.value) {
throw new NotFoundException(ResponseMessages.agent.error.walletDoesNotExists);
}

if (getApiKeyResult.status === PromiseResult.REJECTED) {
throw new InternalServerErrorException(`Failed to get API key: ${getApiKeyResult.reason}`);
}

if (orgAgentResult.status === 'rejected') {
if (orgAgentResult.status === PromiseResult.REJECTED) {
throw new InternalServerErrorException(`Failed to get agent information: ${orgAgentResult.reason}`);
}

Expand Down
9 changes: 7 additions & 2 deletions apps/organization/repositories/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,16 @@ export class OrganizationRepository {

async getOrganizationDetails(orgId: string): Promise<organisation> {
try {
return this.prisma.organisation.findFirstOrThrow({
if (!orgId) {
throw new NotFoundException(ResponseMessages.organisation.error.orgNotFound);
}
const orgDetails = await this.prisma.organisation.findFirst({
where: {
id: orgId
}
});

return orgDetails;
} catch (error) {
this.logger.error(`error: ${JSON.stringify(error)}`);
throw new InternalServerErrorException(error);
Expand Down Expand Up @@ -833,7 +838,7 @@ export class OrganizationRepository {
// If no references are found, delete the organization
const deleteOrg = await prisma.organisation.delete({ where: { id } });

return {deletedUserActivity, deletedUserOrgRole, deletedOrgInvitations, deletedNotification, deleteOrg};
return {deletedUserActivity, deletedUserOrgRole, deletedOrgInvitations, deletedNotification, deleteOrg};
});
// return result;
} catch (error) {
Expand Down
5 changes: 3 additions & 2 deletions libs/common/src/response-messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const ResponseMessages = {
deleteOrg: 'Organization not found',
deleteOrgInvitation: 'Organization does not have access to delete this invitation',
notFound: 'Organization agent not found',
orgNotFound: 'Organization not found',
orgNotFound: 'Organization does not exists',
orgDataNotFoundInkeycloak: 'Organization not found in keycloak',
orgNotMatch: 'Organization does not have access',
invitationStatusInvalid: 'Unable to delete invitation with accepted/rejected status',
Expand Down Expand Up @@ -263,7 +263,8 @@ export const ResponseMessages = {
failedApiKey: 'Failed to encrypt API key',
failedOrganization: 'Failed to fetch organization agent type details',
promiseReject: 'One or more promises were rejected.',
orgAgentNotFound: 'Org agent type not found'
orgAgentNotFound: 'Org agent type not found',
walletDoesNotExists: 'Organization wallet does not exists'
}
},
connection: {
Expand Down

0 comments on commit a6301b9

Please sign in to comment.