Skip to content

Commit

Permalink
Merge branch 'credebl:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheetal-ayanworks authored May 14, 2024
2 parents 7127ade + 480c31f commit 3676d8c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
10 changes: 4 additions & 6 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,10 @@ export class AgentServiceService {
}

delete createDidPayload.isPrimaryDid;

const didDetails = await this.commonService.httpPost(url, createDidPayload, { headers: { authorization: getApiKey } });

const didDetails = await this.commonService.httpPost(url, createDidPayload, {
headers: { authorization: getApiKey }
});

if (!didDetails) {
if (!didDetails || Object.keys(didDetails).length === 0) {
throw new InternalServerErrorException(ResponseMessages.agent.error.createDid, {
cause: new Error(),
description: ResponseMessages.errorMessages.serverError
Expand All @@ -877,7 +875,7 @@ export class AgentServiceService {
const createdDidDetails = {
orgId,
did: didDetails.did,
didDocument: didDetails.didDocument,
didDocument: didDetails.didDocument || didDetails.didDoc,
isPrimaryDid,
orgAgentId: agentDetails.id,
userId: user.id
Expand Down
5 changes: 2 additions & 3 deletions apps/api-gateway/src/organization/organization.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,10 @@ export class OrganizationController {
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiBearerAuth()
async setPrimaryDid(@Param('orgId') orgId: string, @Body() primaryDidPayload: PrimaryDid, @Res() res: Response): Promise<Response> {
const orgData = await this.organizationService.setPrimaryDid(primaryDidPayload, orgId);
await this.organizationService.setPrimaryDid(primaryDidPayload, orgId);
const finalResponse: IResponse = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.organisation.success.primaryDid,
data: orgData
message: ResponseMessages.organisation.success.primaryDid
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}
Expand Down
10 changes: 6 additions & 4 deletions apps/api-gateway/src/verification/dto/request-proof.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,17 @@ export class RequestProofDto extends ProofPayload {
@ApiProperty({
'example':
{
'indy': [
{
'indy': {
'attributes': [
{
attributeName: 'attributeName',
condition: '>=',
value: 'predicates',
credDefId: 'string',
schemaId: 'string'
}
]
}
]
}
},
type: () => [IndyDto]
})
Expand Down
5 changes: 5 additions & 0 deletions apps/organization/interfaces/organization.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ export interface IDidDetails {
did: string;
didDocument: Prisma.JsonValue;
orgAgentId: string;
}

export interface IPrimaryDidDetails extends IPrimaryDid {
id: string,
didDocument: Prisma.JsonValue
}
22 changes: 18 additions & 4 deletions apps/organization/repositories/organization.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Injectable, Logger, NotFoundException } from '@nestjs/common';
import { Prisma, agent_invitations, org_agents, org_invitations, user_org_roles } from '@prisma/client';

import { CreateOrganizationDto } from '../dtos/create-organization.dto';
import { IDidDetails, IDidList, IGetOrgById, IGetOrganization, IUpdateOrganization } from '../interfaces/organization.interface';
import { IDidDetails, IDidList, IGetOrgById, IGetOrganization, IPrimaryDidDetails, IUpdateOrganization } from '../interfaces/organization.interface';
import { InternalServerErrorException } from '@nestjs/common';
import { Invitation, SortValue } from '@credebl/enum/enum';
import { PrismaService } from '@credebl/prisma-service';
Expand Down Expand Up @@ -779,8 +779,9 @@ export class OrganizationRepository {
}
}

async setOrgsPrimaryDid(primaryDid:string, orgId:string, id:string): Promise<string> {
async setOrgsPrimaryDid(primaryDidDetails: IPrimaryDidDetails): Promise<string> {
try {
const {did, didDocument, id, orgId} = primaryDidDetails;
await this.prisma.$transaction([
this.prisma.org_dids.update({
where: {
Expand All @@ -790,13 +791,13 @@ export class OrganizationRepository {
isPrimaryDid: true
}
}),

this.prisma.org_agents.update({
where: {
orgId
},
data: {
orgDid: primaryDid
orgDid: did,
didDocument
}
})
]);
Expand All @@ -807,6 +808,19 @@ export class OrganizationRepository {
}
}

async getDidDetailsByDid(did:string): Promise<IDidDetails> {
try {
return this.prisma.org_dids.findFirstOrThrow({
where: {
did
}
});
} catch (error) {
this.logger.error(`[getDidDetailsByDid] - get DID details: ${JSON.stringify(error)}`);
throw error;
}
}

async getPerviousPrimaryDid(orgId:string): Promise<IDidDetails> {
try {
return this.prisma.org_dids.findFirstOrThrow({
Expand Down
19 changes: 15 additions & 4 deletions apps/organization/src/organization.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CreateOrganizationDto } from '../dtos/create-organization.dto';
import { BulkSendInvitationDto } from '../dtos/send-invitation.dto';
import { UpdateInvitationDto } from '../dtos/update-invitation.dt';
import { Invitation, OrgAgentType, transition } from '@credebl/enum/enum';
import { IGetOrgById, IGetOrganization, IUpdateOrganization, IOrgAgent, IClientCredentials, ICreateConnectionUrl, IOrgRole, IDidList } from '../interfaces/organization.interface';
import { IGetOrgById, IGetOrganization, IUpdateOrganization, IOrgAgent, IClientCredentials, ICreateConnectionUrl, IOrgRole, IDidList, IPrimaryDidDetails } from '../interfaces/organization.interface';
import { UserActivityService } from '@credebl/user-activity';
import { CommonConstants } from '@credebl/common/common.constant';
import { ClientRegistrationService } from '@credebl/client-registration/client-registration.service';
Expand Down Expand Up @@ -175,17 +175,28 @@ export class OrganizationService {
if (orgAgentDetails.orgDid === did) {
throw new ConflictException(ResponseMessages.organisation.error.primaryDid);
}

//check user DID exist in the organization's did list
const organizationDidList = await this.organizationRepository.getAllOrganizationDid(orgId);
const isDidMatch = organizationDidList.some(item => item.did === did);

if (!isDidMatch) {
throw new NotFoundException(ResponseMessages.organisation.error.didNotFound);
}
const didDetails = await this.organizationRepository.getDidDetailsByDid(did);

const getExistingPrimaryDid = await this.organizationRepository.getPerviousPrimaryDid(orgId);
if (!didDetails) {
throw new NotFoundException(ResponseMessages.organisation.error.didNotFound);
}
const primaryDidDetails: IPrimaryDidDetails = {
did,
orgId,
id,
didDocument: didDetails.didDocument
};

const setPrimaryDid = await this.organizationRepository.setOrgsPrimaryDid(did, orgId, id);
const setPrimaryDid = await this.organizationRepository.setOrgsPrimaryDid(primaryDidDetails);

const getExistingPrimaryDid = await this.organizationRepository.getPerviousPrimaryDid(orgId);


if (!getExistingPrimaryDid) {
Expand Down

0 comments on commit 3676d8c

Please sign in to comment.