Skip to content

Commit

Permalink
Merge pull request #130 from Tusharmahajan12/new_oblf
Browse files Browse the repository at this point in the history
corrected the limit in search cohort
  • Loading branch information
vijaykhollam authored Jan 13, 2025
2 parents 4e02e3b + 3da4121 commit 1e4a3ff
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/adapters/postgres/cohort-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,11 +498,23 @@ export class PostgresCohortService {
let { limit, sort, offset, filters } = cohortSearchDto;

offset = offset || 0;
limit = limit || 200;

const emptyValueKeys = {};
let emptyKeysString = "";

const MAX_LIMIT = 200;

// Validate the limit parameter
if (limit > MAX_LIMIT) {
return APIResponse.error(
response,
apiId,
`Limit exceeds maximum allowed value of ${MAX_LIMIT}`,
`Limit exceeded`,
HttpStatus.BAD_REQUEST
);
}
//Get all cohorts fields
const cohortAllKeys = this.cohortRepository.metadata.columns.map(
(column) => column.propertyName,
Expand Down Expand Up @@ -602,12 +614,7 @@ export class PostgresCohortService {
await this.cohortMembersRepository.findAndCount({
where: whereClause,
});

let userExistCohortGroup;
if (limit > 0) {
userExistCohortGroup = data.slice(offset, offset + limit);
}
userExistCohortGroup = data
const userExistCohortGroup = data.slice(offset, offset + limit);
count = totalCount;

let cohortIds = userExistCohortGroup.map(cohortId => cohortId.cohortId);
Expand Down Expand Up @@ -649,11 +656,7 @@ export class PostgresCohortService {
order,
});

let cohortData;
if (limit > 0) {
cohortData = data.slice(offset, offset + limit);
}
cohortData = data
const cohortData = data.slice(offset, offset + limit);
count = totalCount;

for (let data of cohortData) {
Expand Down

0 comments on commit 1e4a3ff

Please sign in to comment.