diff --git a/src/adapters/postgres/cohort-adapter.ts b/src/adapters/postgres/cohort-adapter.ts index 8f23cf6e..fa61072a 100644 --- a/src/adapters/postgres/cohort-adapter.ts +++ b/src/adapters/postgres/cohort-adapter.ts @@ -9,7 +9,7 @@ import { CohortCreateDto } from "src/cohort/dto/cohort-create.dto"; import { CohortUpdateDto } from "src/cohort/dto/cohort-update.dto"; import { FieldValuesDto } from "src/fields/dto/field-values.dto"; import { FieldValuesUpdateDto } from "src/fields/dto/field-values-update.dto"; -import { IsNull, Not, Repository, getConnection, getRepository } from "typeorm"; +import { IsNull, Not, Repository, getConnection, getRepository, In } from "typeorm"; import { Cohort } from "src/cohort/entities/cohort.entity"; import { Fields } from "src/fields/entities/fields.entity"; import { InjectRepository } from "@nestjs/typeorm"; @@ -487,24 +487,8 @@ export class PostgresCohortService { }); } - if (whereClause['userId'] && !isUUID(whereClause['userId'])) { - return APIResponse.error( - response, - apiId, - `Invalid User ID format. It must be a valid UUID`, - `Invalid userId`, - (HttpStatus.BAD_REQUEST) - ) - } - - if (whereClause['cohortId'] && !isUUID(whereClause['cohortId'])) { - return APIResponse.error( - response, - apiId, - `Invalid Cohort ID format. It must be a valid UUID`, - `Invalid cohortID`, - (HttpStatus.BAD_REQUEST) - ) + if (whereClause['parentId']) { + whereClause['parentId'] = In(whereClause['parentId']); } let results = { @@ -557,20 +541,21 @@ export class PostgresCohortService { let customFieldsData = await this.getCohortDataWithCustomfield(data.cohortId); cohortAllData['customFields'] = customFieldsData - results.cohortDetails.push({ cohortData: cohortAllData }); + results.cohortDetails.push(cohortAllData); } } else { const [data, totalcount] = await this.cohortRepository.findAndCount({ where: whereClause, skip: offset }); + const cohortData = data.slice(offset, offset + (limit)); count = totalcount; for (let data of cohortData) { let customFieldsData = await this.getCohortDataWithCustomfield(data.cohortId, data.type); data['customFields'] = customFieldsData || []; - results.cohortDetails.push({ cohortData: data }) + results.cohortDetails.push(data) } } diff --git a/src/cohort/cohort.controller.ts b/src/cohort/cohort.controller.ts index 0907e458..123fd077 100644 --- a/src/cohort/cohort.controller.ts +++ b/src/cohort/cohort.controller.ts @@ -117,7 +117,7 @@ export class CohortController { @UseFilters(new AllExceptionsFilter(APIID.COHORT_LIST)) @Post("/search") @ApiBasicAuth("access-token") - @ApiBody({ type: CohortSearchDto }) + // @ApiBody({ type: CohortSearchDto }) @ApiOkResponse({ description: "Cohort list" }) @ApiBadRequestResponse({ description: "Bad request." }) @ApiInternalServerErrorResponse({ description: "Internal Server Error." }) diff --git a/src/cohort/dto/cohort-search.dto.ts b/src/cohort/dto/cohort-search.dto.ts index a59b14fd..35c28dd2 100644 --- a/src/cohort/dto/cohort-search.dto.ts +++ b/src/cohort/dto/cohort-search.dto.ts @@ -1,9 +1,9 @@ import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger"; -import { IsBoolean, IsNotEmpty, IsNumber, IsNumberString, IsObject, IsOptional, IsString, IsUUID, ValidationArguments, ValidationOptions, registerDecorator } from "class-validator"; +import { IsArray, IsBoolean, IsNotEmpty, IsNumber, IsNumberString, IsObject, IsOptional, IsString, IsUUID, ValidationArguments, ValidationOptions, registerDecorator } from "class-validator"; import { CohortDto } from "./cohort.dto"; import { Expose } from "class-transformer"; -export class setFilters { +export class filtersProperty { //userIdBy @ApiProperty({ type: String, @@ -40,17 +40,18 @@ export class setFilters { @IsNotEmpty() name?: string; - //name + //parentId @ApiProperty({ - type: String, + type: [String], description: "Parent Id", - default: "", + default: [], }) @Expose() @IsOptional() - @IsString() - @IsNotEmpty() - parentId?: string; + @IsArray() + @IsNotEmpty({ each: true }) + @IsUUID(undefined, { each: true }) + parentId?: string[]; } export class CohortSearchDto { @@ -69,11 +70,11 @@ export class CohortSearchDto { page: number; @ApiProperty({ - type: setFilters, + type: filtersProperty, description: "Filters", }) @IsObject() - filters: setFilters; + filters: filtersProperty; constructor(partial: Partial) { Object.assign(this, partial);