Skip to content

Commit

Permalink
fix: schemaId validation issues
Browse files Browse the repository at this point in the history
Signed-off-by: KulkarniShashank <[email protected]>
  • Loading branch information
KulkarniShashank committed Apr 19, 2024
1 parent c295851 commit 16b65ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
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

0 comments on commit 16b65ae

Please sign in to comment.