chore: added input validation to search query (#3921)
This commit is contained in:
@@ -750,3 +750,8 @@ export const DATABASE_TABLE_NOT_EXIST =
|
|||||||
* (InfraConfigService)
|
* (InfraConfigService)
|
||||||
*/
|
*/
|
||||||
export const POSTHOG_CLIENT_NOT_INITIALIZED = 'posthog/client_not_initialized';
|
export const POSTHOG_CLIENT_NOT_INITIALIZED = 'posthog/client_not_initialized';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inputs supplied are invalid
|
||||||
|
*/
|
||||||
|
export const INVALID_PARAMS = 'invalid_parameters' as const;
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
HttpStatus,
|
||||||
|
Param,
|
||||||
|
Query,
|
||||||
|
UseGuards,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { TeamCollectionService } from './team-collection.service';
|
import { TeamCollectionService } from './team-collection.service';
|
||||||
import * as E from 'fp-ts/Either';
|
import * as E from 'fp-ts/Either';
|
||||||
import { ThrottlerBehindProxyGuard } from 'src/guards/throttler-behind-proxy.guard';
|
import { ThrottlerBehindProxyGuard } from 'src/guards/throttler-behind-proxy.guard';
|
||||||
@@ -7,6 +14,8 @@ import { RequiresTeamRole } from 'src/team/decorators/requires-team-role.decorat
|
|||||||
import { TeamMemberRole } from '@prisma/client';
|
import { TeamMemberRole } from '@prisma/client';
|
||||||
import { RESTTeamMemberGuard } from 'src/team/guards/rest-team-member.guard';
|
import { RESTTeamMemberGuard } from 'src/team/guards/rest-team-member.guard';
|
||||||
import { throwHTTPErr } from 'src/utils';
|
import { throwHTTPErr } from 'src/utils';
|
||||||
|
import { RESTError } from 'src/types/RESTError';
|
||||||
|
import { INVALID_PARAMS } from 'src/errors';
|
||||||
|
|
||||||
@UseGuards(ThrottlerBehindProxyGuard)
|
@UseGuards(ThrottlerBehindProxyGuard)
|
||||||
@Controller({ path: 'team-collection', version: '1' })
|
@Controller({ path: 'team-collection', version: '1' })
|
||||||
@@ -26,8 +35,15 @@ export class TeamCollectionController {
|
|||||||
@Query('take') take: string,
|
@Query('take') take: string,
|
||||||
@Query('skip') skip: string,
|
@Query('skip') skip: string,
|
||||||
) {
|
) {
|
||||||
|
if (!teamID || !searchQuery) {
|
||||||
|
return <RESTError>{
|
||||||
|
message: INVALID_PARAMS,
|
||||||
|
statusCode: HttpStatus.BAD_REQUEST,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const res = await this.teamCollectionService.searchByTitle(
|
const res = await this.teamCollectionService.searchByTitle(
|
||||||
searchQuery,
|
searchQuery.trim(),
|
||||||
teamID,
|
teamID,
|
||||||
parseInt(take),
|
parseInt(take),
|
||||||
parseInt(skip),
|
parseInt(skip),
|
||||||
|
|||||||
Reference in New Issue
Block a user