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

fix: schemaId validation issues #673

Closed
wants to merge 1 commit into from
Closed
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
18 changes: 17 additions & 1 deletion apps/api-gateway/src/schema/dtos/get-all-schema.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { SortValue } from '../../enum';
import { Transform, Type } from 'class-transformer';
import { IsEnum, IsOptional } from 'class-validator';
import { IsEnum, IsNotEmpty, IsOptional, IsString, IsUUID } from 'class-validator';
import { trim } from '@credebl/common/cast.helper';
import { CredDefSortFields, SortFields } from 'apps/ledger/src/schema/enum/schema.enum';

Expand Down Expand Up @@ -100,4 +100,20 @@ export class GetAllSchemaByPlatformDto {
@ApiProperty({ required: false })
@IsOptional()
sortByValue: string = SortValue.DESC;
}

export class GetSchema {

@ApiProperty()
@IsUUID()
@IsString({ message: 'orgId must be a string' })
@IsNotEmpty({ message: 'please provide valid orgId' })
@Transform(({ value }) => trim(value))
orgId: string;

@ApiProperty()
@IsString({ message: 'schemaId must be a string' })
@IsNotEmpty({ message: 'please provide valid schemaId' })
@Transform(({ value }) => trim(value))
schemaId: string;
}
22 changes: 15 additions & 7 deletions apps/api-gateway/src/schema/schema.controller.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller, Logger, Post, Body, HttpStatus, UseGuards, Get, Query, BadRequestException, Res, UseFilters, Param } from '@nestjs/common';
import { Controller, Logger, Post, Body, HttpStatus, UseGuards, Get, Query, BadRequestException, Res, UseFilters, Param, UsePipes, ValidationPipe } from '@nestjs/common';
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable camelcase */
import { ApiOperation, ApiResponse, ApiTags, ApiBearerAuth, ApiForbiddenResponse, ApiUnauthorizedResponse, ApiQuery } from '@nestjs/swagger';
import { ApiOperation, ApiResponse, ApiTags, ApiBearerAuth, ApiForbiddenResponse, ApiUnauthorizedResponse, ApiQuery, ApiParam } from '@nestjs/swagger';
import { SchemaService } from './schema.service';
import { AuthGuard } from '@nestjs/passport';
import { ApiResponseDto } from '../dtos/apiResponse.dto';
Expand All @@ -12,7 +12,7 @@ import { Response } from 'express';
import { User } from '../authz/decorators/user.decorator';
import { ISchemaSearchPayload } from '../interfaces/ISchemaSearch.interface';
import { ResponseMessages } from '@credebl/common/response-messages';
import { GetAllSchemaDto, GetCredentialDefinitionBySchemaIdDto } from './dtos/get-all-schema.dto';
import { GetAllSchemaDto, GetCredentialDefinitionBySchemaIdDto, GetSchema } from './dtos/get-all-schema.dto';
import { OrgRoles } from 'libs/org-roles/enums';
import { Roles } from '../authz/decorators/roles.decorator';
import { IUserRequestInterface } from './interfaces';
Expand All @@ -33,23 +33,31 @@ export class SchemaController {
private readonly logger = new Logger('SchemaController');

@Get('/:orgId/schemas/:schemaId')
@UsePipes(new ValidationPipe())
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER)
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
@ApiOperation({
summary: 'Get schema information from the ledger using its schema ID.',
description: 'Get schema information from the ledger using its schema ID.'
})
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
@ApiParam({
name: 'schemaId',
required: true
})
@ApiParam({
name: 'orgId',
required: true
})
async getSchemaById(
@Res() res: Response,
@Param('orgId') orgId: string,
@Param('schemaId') schemaId: string
@Param() getSchema: GetSchema
): Promise<object> {

if (!schemaId) {
if (!getSchema.schemaId) {
throw new BadRequestException(ResponseMessages.schema.error.invalidSchemaId);
}
const schemaDetails = await this.appService.getSchemaById(schemaId, orgId);
const schemaDetails = await this.appService.getSchemaById(getSchema.schemaId, getSchema.orgId);
const finalResponse: IResponseType = {
statusCode: HttpStatus.OK,
message: ResponseMessages.schema.success.fetch,
Expand Down
Loading