Skip to content

Commit

Permalink
feat: get w3c schema details by schema id (#808)
Browse files Browse the repository at this point in the history
* feat: get w3c schema details by schema id

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

* refactor: applied validations

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

---------

Signed-off-by: bhavanakarwade <[email protected]>
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
bhavanakarwade authored and KulkarniShashank committed Sep 12, 2024
1 parent 0ba7950 commit d871a2a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
3 changes: 2 additions & 1 deletion apps/api-gateway/src/schema/schema.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { OrgRolesGuard } from '../authz/guards/org-roles.guard';
import { GenericSchemaDTO } from '../dtos/create-schema.dto';
import { CustomExceptionFilter } from 'apps/api-gateway/common/exception-handler';
import { CredDefSortFields, SortFields } from '@credebl/enum/enum';
import { TrimStringParamPipe } from '@credebl/common/cast.helper';

@UseFilters(CustomExceptionFilter)
@Controller('orgs')
Expand All @@ -43,7 +44,7 @@ export class SchemaController {
async getSchemaById(
@Res() res: Response,
@Param('orgId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidOrgId); }})) orgId: string,
@Param('schemaId') schemaId: string
@Param('schemaId', TrimStringParamPipe) schemaId: string
): Promise<Response> {

if (!schemaId) {
Expand Down
64 changes: 40 additions & 24 deletions apps/ledger/src/schema/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
Inject,
ConflictException,
Injectable,
NotAcceptableException, NotFoundException
NotAcceptableException, NotFoundException,
ForbiddenException
} from '@nestjs/common';
import { ClientProxy, RpcException } from '@nestjs/microservices';
import { BaseService } from 'libs/service/base.service';
Expand Down Expand Up @@ -667,34 +668,49 @@ export class SchemaService extends BaseService {
async getSchemaById(schemaId: string, orgId: string): Promise<schema> {

try {
const { agentEndPoint } = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
const getAgentDetails = await this.schemaRepository.getAgentType(orgId);
const [{agentEndPoint}, getAgentDetails, getSchemaDetails] = await Promise.all([
this.schemaRepository.getAgentDetailsByOrgId(orgId),
this.schemaRepository.getAgentType(orgId),
this.schemaRepository.getSchemaBySchemaId(schemaId)
]);

if (!getSchemaDetails) {
throw new NotFoundException(ResponseMessages.schema.error.notFound);
}

const orgAgentType = await this.schemaRepository.getOrgAgentType(getAgentDetails.org_agents[0].orgAgentTypeId);

if (getSchemaDetails?.orgId !== orgId) {
throw new ForbiddenException(ResponseMessages.organisation.error.orgNotMatch);
}

let schemaResponse;
if (OrgAgentType.DEDICATED === orgAgentType) {
const getSchemaPayload = {
schemaId,
orgId,
agentEndPoint,
agentType: OrgAgentType.DEDICATED
};
schemaResponse = await this._getSchemaById(getSchemaPayload);
} else if (OrgAgentType.SHARED === orgAgentType) {
const { tenantId } = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
const getSchemaPayload = {
tenantId,
method: 'getSchemaById',
payload: { schemaId },
agentType: OrgAgentType.SHARED,
agentEndPoint,
orgId
};
schemaResponse = await this._getSchemaById(getSchemaPayload);
if (getSchemaDetails?.type === SchemaType.INDY) {
if (OrgAgentType.DEDICATED === orgAgentType) {
const getSchemaPayload = {
schemaId,
orgId,
agentEndPoint,
agentType: OrgAgentType.DEDICATED
};
schemaResponse = await this._getSchemaById(getSchemaPayload);
} else if (OrgAgentType.SHARED === orgAgentType) {
const { tenantId } = await this.schemaRepository.getAgentDetailsByOrgId(orgId);
const getSchemaPayload = {
tenantId,
method: 'getSchemaById',
payload: { schemaId },
agentType: OrgAgentType.SHARED,
agentEndPoint,
orgId
};
schemaResponse = await this._getSchemaById(getSchemaPayload);
}
return schemaResponse.response;
} else if (getSchemaDetails?.type === SchemaType.W3C_Schema) {
return getSchemaDetails;
}
return schemaResponse.response;


} catch (error) {
this.logger.error(`Error in getting schema by id: ${error}`);
if (error && error?.status && error?.status?.message && error?.status?.message?.error) {
Expand Down

0 comments on commit d871a2a

Please sign in to comment.