Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: get w3c schema details by schema id #808

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
bhavanakarwade marked this conversation as resolved.
Show resolved Hide resolved
): 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