Skip to content

Commit cad2ce0

Browse files
bhavanakarwadeKambleSahil3
authored andcommitted
fix: Parameter validations (#1138)
* fix: added api param validations Signed-off-by: bhavanakarwade <[email protected]> * fix: removed unnecessary validations Signed-off-by: bhavanakarwade <[email protected]> * fix:resolved validations issue Signed-off-by: bhavanakarwade <[email protected]> * added comment on function for understanding Signed-off-by: bhavanakarwade <[email protected]> * fix: resolve orgid validations Signed-off-by: bhavanakarwade <[email protected]> * fix: added response message Signed-off-by: bhavanakarwade <[email protected]> * fix: added space in response messages Signed-off-by: bhavanakarwade <[email protected]> --------- Signed-off-by: bhavanakarwade <[email protected]> Signed-off-by: Sahil Kamble <[email protected]>
1 parent 4cc4990 commit cad2ce0

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

apps/api-gateway/src/credential-definition/dto/create-cred-defs.dto.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { IsBoolean, IsDefined, IsNotEmpty, IsOptional, IsString } from 'class-validator';
2-
32
import { ApiProperty } from '@nestjs/swagger';
3+
import { Transform } from 'class-transformer';
4+
import { trim } from '@credebl/common/cast.helper';
45

56
export class CreateCredentialDefinitionDto {
67

78
@ApiProperty({ 'example': 'default' })
8-
@IsDefined({ message: 'Tag is required.' })
9+
@IsDefined({ message: 'Tag is required' })
910
@IsNotEmpty({ message: 'Please provide a tag' })
10-
@IsString({ message: 'Tag id should be string' })
11+
@IsString({ message: 'Tag should be string' })
1112
tag: string;
1213

1314
@ApiProperty({ 'example': 'WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0' })
14-
@IsDefined({ message: 'schemaLedgerId is required.' })
15-
@IsNotEmpty({ message: 'Please provide a schema id' })
15+
@IsDefined({ message: 'schemaLedgerId is required' })
16+
@IsNotEmpty({ message: 'Please provide valid schema ledger Id' })
17+
@Transform(({ value }) => trim(value))
1618
@IsString({ message: 'Schema id should be string' })
1719
schemaLedgerId: string;
1820

apps/api-gateway/src/issuance/dtos/issuance.dto.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
IsOptional,
1515
IsString,
1616
IsUrl,
17+
IsUUID,
1718
MaxLength,
1819
ValidateNested
1920
} from 'class-validator';
@@ -647,6 +648,7 @@ export class FileQuery {
647648
@ApiProperty({ required: true })
648649
@IsString({ message: 'fileId should be string' })
649650
@IsNotEmpty({ message: 'fileId Id is required' })
651+
@IsUUID('4', { message: 'Invalid format for file Id' })
650652
@Transform(({ value }) => trim(value))
651653
fileId: string;
652654
}

apps/api-gateway/src/issuance/issuance.controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { IGetAllIssuedCredentialsDto } from './dtos/get-all-issued-credentials.d
7373
import { IssueCredentialDto } from './dtos/multi-connection.dto';
7474
import { SchemaType } from '@credebl/enum/enum';
7575
import { CommonConstants } from '../../../../libs/common/src/common.constant';
76+
import { TrimStringParamPipe } from '@credebl/common/cast.helper';
7677
@Controller()
7778
@UseFilters(CustomExceptionFilter)
7879
@ApiTags('credentials')
@@ -169,7 +170,7 @@ export class IssuanceController {
169170
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER, OrgRoles.HOLDER)
170171
async getIssueCredentialsbyCredentialRecordId(
171172
@User() user: IUserRequest,
172-
@Param('credentialRecordId') credentialRecordId: string,
173+
@Param('credentialRecordId', TrimStringParamPipe, new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.issuance.error.invalidCredentialRecordId); }})) credentialRecordId: string,
173174
@Param('orgId') orgId: string,
174175
@Res() res: Response
175176
): Promise<Response> {

apps/api-gateway/src/organization/organization.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class OrganizationController {
108108
description: 'Retrieve the roles details for a specific organization.'
109109
})
110110
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
111-
@UseGuards(AuthGuard('jwt'))
111+
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
112112
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
113113
@ApiBearerAuth()
114114
async getOrgRoles(

apps/issuance/src/issuance.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ export class IssuanceService {
591591
this.logger.error(`[getIssueCredentialsbyCredentialRecordId] - error in get credentials : ${JSON.stringify(error)}`);
592592
if (error && error?.status && error?.status?.message && error?.status?.message?.error) {
593593
throw new RpcException({
594-
message: error?.status?.message?.error?.reason ? error?.status?.message?.error?.reason : error?.status?.message?.error,
594+
message: error?.status?.message?.error?.reason || error?.status?.message?.error?.message || error?.status?.message?.error,
595595
statusCode: error?.status?.code
596596
});
597597

libs/common/src/response-messages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ export const ResponseMessages = {
307307
fileDetailsAndFileData:'File details and File data fetched successfully'
308308
},
309309
error: {
310+
invalidCredentialRecordId: 'Please provide valid credential Record Id',
310311
exists: 'Credentials is already exist',
311312
credentialsNotFound: 'Credentials not found',
312313
agentEndPointNotFound: 'Agent details not found',

0 commit comments

Comments
 (0)