From 2357e63ff3d4c2caaddcdd8ba7a560e7c49fac8e Mon Sep 17 00:00:00 2001 From: Ankita Patidar Date: Thu, 25 Apr 2024 16:30:32 +0530 Subject: [PATCH] update validation on creddef field, optional for jsonld Signed-off-by: Ankita Patidar --- .../src/dtos/send-proof-request.dto.ts | 30 +++++++++---------- .../src/issuance/dtos/issuance.dto.ts | 5 ++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/apps/api-gateway/src/dtos/send-proof-request.dto.ts b/apps/api-gateway/src/dtos/send-proof-request.dto.ts index c24cb307b..a8d1600f5 100644 --- a/apps/api-gateway/src/dtos/send-proof-request.dto.ts +++ b/apps/api-gateway/src/dtos/send-proof-request.dto.ts @@ -1,26 +1,26 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsArray, IsString, IsNotEmpty, IsObject} from 'class-validator'; +import { IsArray, IsString, IsNotEmpty, IsObject } from 'class-validator'; -export class SendProofRequest { +export class SendProofRequest { @ApiProperty({ 'example': '3fa85f64-5717-4562-b3fc-2c963f66afa6' }) - @IsString({message:'connection id must be string'}) - @IsNotEmpty({message:'please provide valid connection Id'}) + @IsString({ message: 'connection id must be string' }) + @IsNotEmpty({ message: 'please provide valid connection Id' }) connectionId: string; @ApiProperty({ 'example': [ -{ - attributeName: 'attributeName', - condition: '>=', - value: 'predicates', - credDefId: '', - credentialName:'' - } -] + { + attributeName: 'attributeName', + condition: '>=', + value: 'predicates', + credDefId: '', + credentialName: '' + } + ] }) - @IsArray({message:'attributes must be in array'}) - @IsObject({each:true}) - @IsNotEmpty({message:'please provide valid attributes'}) + @IsArray({ message: 'attributes must be in array' }) + @IsObject({ each: true }) + @IsNotEmpty({ message: 'please provide valid attributes' }) attributes: object[]; } \ No newline at end of file diff --git a/apps/api-gateway/src/issuance/dtos/issuance.dto.ts b/apps/api-gateway/src/issuance/dtos/issuance.dto.ts index 216fcaeec..a8273c4f5 100644 --- a/apps/api-gateway/src/issuance/dtos/issuance.dto.ts +++ b/apps/api-gateway/src/issuance/dtos/issuance.dto.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/array-type */ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { ArrayMaxSize, ArrayMinSize, IsArray, IsBoolean, IsDefined, IsEmail, IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, MaxLength, ValidateNested } from 'class-validator'; +import { ArrayMaxSize, ArrayMinSize, IsArray, IsBoolean, IsDefined, IsEmail, IsEnum, IsNotEmpty, IsObject, IsOptional, IsString, MaxLength, ValidateIf, ValidateNested } from 'class-validator'; import { IsCredentialJsonLdContext, SingleOrArray } from '../utils/helper'; import { IssueCredentialType, JsonLdCredentialDetailCredentialStatusOptions, JsonLdCredentialDetailOptionsOptions, JsonObject } from '../interfaces'; import { Transform, Type } from 'class-transformer'; @@ -125,6 +125,7 @@ export class Attribute { } export class CredentialsIssuanceDto { + @ValidateIf((obj) => obj.credentialType === IssueCredentialType.INDY) @ApiProperty({ example: 'string' }) @IsNotEmpty({ message: 'Credential definition Id is required' }) @IsString({ message: 'Credential definition id should be string' }) @@ -221,7 +222,7 @@ export class OOBIssueCredentialDto extends CredentialsIssuanceDto { @IsNotEmpty() @IsBoolean({message: 'isShortenUrl must be boolean'}) isShortenUrl?: boolean; - + @ApiProperty() @IsNotEmpty({ message: 'Please provide valid credential' })