Skip to content

Commit

Permalink
Merge pull request #155 from souravbhowmik1999/responceBody
Browse files Browse the repository at this point in the history
Cohort Member: Response body changes
  • Loading branch information
vijaykhollam authored May 10, 2024
2 parents 6800b22 + 6853810 commit a285e14
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
26 changes: 10 additions & 16 deletions src/adapters/postgres/cohortMembers-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,14 @@ export class PostgresCohortMembersService {
role: data?.role,
district: data?.district,
state: data?.state,
mobile: data?.mobile,
customField: [],
mobile: data?.mobile
};

if (fieldShowHide === "false") {
results.userDetails.push(userDetails);
} else {
const fieldValues = await this.getFieldandFieldValues(data.userId);
userDetails.customField.push(fieldValues);
const fieldValues = await this.getFieldandFieldValues(data.userId);
userDetails['customField'] = fieldValues;
results.userDetails.push(userDetails);
}
}
Expand Down Expand Up @@ -159,11 +158,9 @@ export class PostgresCohortMembersService {
let { limit, page, filters } = cohortMembersSearchDto;
let offset = 0;
if (page > 1) {
offset = parseInt(limit) * (page - 1);
}
if (limit.trim() === "") {
limit = "0";
offset = limit * (page - 1);
}

const whereClause = {};
if (filters && Object.keys(filters).length > 0) {
Object.entries(filters).forEach(([key, value]) => {
Expand Down Expand Up @@ -212,26 +209,23 @@ export class PostgresCohortMembersService {
const [userData] = await this.cohortMembersRepository.findAndCount({
where: whereClause,
skip: offset,
take: parseInt(limit),
take: limit,
});
let results = {
userDetails: [],
};
let results = {};
if (whereClause["cohortId"]) {
let cohortDetails = await this.getUserDetails(
results = await this.getUserDetails(
whereClause["cohortId"],
"cohortId",
"true"
);
results.userDetails.push(cohortDetails);
}

if (whereClause["userId"]) {
let cohortDetails = await this.getUserDetails(
results = await this.getUserDetails(
whereClause["userId"],
"userId",
"true"
);
results.userDetails.push(cohortDetails);
}

return new SuccessResponse({
Expand Down
7 changes: 2 additions & 5 deletions src/cohortMembers/cohortMember.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,10 @@ export class CohortMembersService {

try {
let { limit, page, filters } = cohortMembersSearchDto;
if (!limit) {
limit = "0";
}

let offset = 0;
if (page > 1) {
offset = parseInt(limit) * (page - 1);
offset = limit * (page - 1);
}

const whereClause = {};
Expand All @@ -113,7 +110,7 @@ export class CohortMembersService {

let filterDetails = {
where: data.cohortId,
take: parseInt(limit),
take: limit,
skip: offset,
};

Expand Down
4 changes: 2 additions & 2 deletions src/cohortMembers/dto/cohortMembers-search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";

export class CohortMembersSearchDto {
@ApiProperty({
type: String,
type: Number,
description: "Limit",
})
limit: string;
limit: number;

@ApiProperty({
type: Number,
Expand Down

0 comments on commit a285e14

Please sign in to comment.