Skip to content

Commit 017e901

Browse files
fix: added api param validations (#1121)
* fix: added api param validations Signed-off-by: bhavanakarwade <[email protected]> * fix: removed unnecessary validations Signed-off-by: bhavanakarwade <[email protected]> --------- Signed-off-by: bhavanakarwade <[email protected]>
1 parent 5169969 commit 017e901

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { ClientProxy} from '@nestjs/microservices';
2323
import { BasicMessageDto, QuestionAnswerWebhookDto, QuestionDto} from './dtos/question-answer.dto';
2424
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2525
import { user } from '@prisma/client';
26+
import { TrimStringParamPipe } from '@credebl/common/cast.helper';
2627
@UseFilters(CustomExceptionFilter)
2728
@Controller()
2829
@ApiTags('connections')
@@ -52,8 +53,8 @@ export class ConnectionController {
5253
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
5354
async getConnectionsById(
5455
@User() user: IUserRequest,
55-
@Param('connectionId') connectionId: string,
5656
@Param('orgId') orgId: string,
57+
@Param('connectionId', TrimStringParamPipe, new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.connection.error.invalidConnectionId); }})) connectionId: string,
5758
@Res() res: Response
5859
): Promise<Response> {
5960
const connectionsDetails = await this.connectionService.getConnectionsById(user, connectionId, orgId);
@@ -416,13 +417,13 @@ export class ConnectionController {
416417
* @returns The details of the sent basic message
417418
*/
418419
@Post('/orgs/:orgId/basic-message/:connectionId')
419-
@ApiOperation({ summary: 'Send basic message', description: 'Send a basic message to a specific connection for a specific organization.' })
420-
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
420+
@ApiOperation({ summary: 'Send basic message', description: 'Send a basic message to a specific connection for a specific organization.' })
421+
@UseGuards(AuthGuard('jwt'), OrgRolesGuard)
421422
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN, OrgRoles.ISSUER, OrgRoles.VERIFIER, OrgRoles.MEMBER, OrgRoles.HOLDER, OrgRoles.SUPER_ADMIN, OrgRoles.PLATFORM_ADMIN)
422423
@ApiResponse({ status: HttpStatus.CREATED, description: 'Created', type: ApiResponseDto })
423424
async sendBasicMessage(
424425
@Param('orgId') orgId: string,
425-
@Param('connectionId') connectionId: string,
426+
@Param('connectionId', TrimStringParamPipe, new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.connection.error.invalidConnectionId); }})) connectionId: string,
426427
@Body() basicMessageDto: BasicMessageDto,
427428
@User() reqUser: IUserRequestInterface,
428429
@Res() res: Response

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ export class OrganizationController {
109109
})
110110
@ApiResponse({ status: HttpStatus.OK, description: 'Success', type: ApiResponseDto })
111111
@UseGuards(AuthGuard('jwt'))
112+
@Roles(OrgRoles.OWNER, OrgRoles.ADMIN)
112113
@ApiBearerAuth()
113-
async getOrgRoles(@Param('orgId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(ResponseMessages.organisation.error.invalidOrgId); }})) orgId: string, @User() user: user, @Res() res: Response): Promise<Response> {
114+
async getOrgRoles(
115+
@Param('orgId') orgId: string,
116+
@User() user: user,
117+
@Res() res: Response): Promise<Response> {
114118

115119
const orgRoles = await this.organizationService.getOrgRoles(orgId.trim(), user);
116120

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import { OrgRoles } from 'libs/org-roles/enums';
5050
import { AwsService } from '@credebl/aws/aws.service';
5151
import { PaginationDto } from '@credebl/common/dtos/pagination.dto';
5252
import { UserAccessGuard } from '../authz/guards/user-access-guard';
53+
import { TrimStringParamPipe } from '@credebl/common/cast.helper';
5354

5455
@UseFilters(CustomExceptionFilter)
5556
@Controller('users')
@@ -306,7 +307,7 @@ export class UserController {
306307
@ApiBearerAuth()
307308
async acceptRejectInvitaion(
308309
@Body() acceptRejectInvitation: AcceptRejectInvitationDto,
309-
@Param('invitationId', new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(`Invalid format for InvitationId`); }})) invitationId: string,
310+
@Param('invitationId', TrimStringParamPipe, new ParseUUIDPipe({exceptionFactory: (): Error => { throw new BadRequestException(`Invalid format for InvitationId`); }})) invitationId: string,
310311
@User() reqUser: user,
311312
@Res() res: Response
312313
): Promise<Response> {

apps/api-gateway/src/webhook/dtos/get-webhoook-dto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApiExtraModels, ApiPropertyOptional } from '@nestjs/swagger';
2-
import { IsOptional, IsString } from 'class-validator';
2+
import { IsOptional, IsString, IsUUID } from 'class-validator';
33
import { Transform } from 'class-transformer';
44
import { trim } from '@credebl/common/cast.helper';
55

@@ -15,6 +15,7 @@ export class GetWebhookDto {
1515
@ApiPropertyOptional({example: '3a041d6e-d24c-4ed9-b011-1cfc371a8b8e'})
1616
@IsOptional()
1717
@Transform(({ value }) => trim(value))
18+
@IsUUID('4', { message: 'Please provide valid tenantId' })
1819
@IsString({ message: 'Tenant id must be in string format.' })
1920
tenantId?: string;
2021
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ export const ResponseMessages = {
282282
basicMessage: 'Basic message sent successfully'
283283
},
284284
error: {
285+
invalidConnectionId: 'Invalid format for connectionId',
285286
exists: 'Connection is already exist',
286287
connectionNotFound: 'Connection not found',
287288
agentEndPointNotFound: 'agentEndPoint Not Found',

0 commit comments

Comments
 (0)