diff --git a/apps/api-gateway/src/schema/dtos/get-all-schema.dto.ts b/apps/api-gateway/src/schema/dtos/get-all-schema.dto.ts index e16ec07c2..0a72a7f84 100644 --- a/apps/api-gateway/src/schema/dtos/get-all-schema.dto.ts +++ b/apps/api-gateway/src/schema/dtos/get-all-schema.dto.ts @@ -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'; @@ -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; } \ No newline at end of file diff --git a/apps/api-gateway/src/schema/schema.controller.ts b/apps/api-gateway/src/schema/schema.controller.ts index 15335fa03..c471f4fad 100644 --- a/apps/api-gateway/src/schema/schema.controller.ts +++ b/apps/api-gateway/src/schema/schema.controller.ts @@ -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'; @@ -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'; @@ -33,6 +33,7 @@ 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({ @@ -40,16 +41,23 @@ export class SchemaController { 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 { - 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,