Skip to content

Commit

Permalink
Merge pull request #100 from arati-tekdi/main
Browse files Browse the repository at this point in the history
Added condition for custom field
  • Loading branch information
Shubham4026 authored Nov 23, 2024
2 parents b75a609 + 459c5b9 commit a3c4fcf
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions src/adapters/postgres/cohortMembers-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ export class PostgresCohortMembersService {

return result;
}
//****

public async updateCohortMembers(
cohortMembershipId: string,
loginUser: any,
Expand Down Expand Up @@ -694,20 +694,45 @@ export class PostgresCohortMembersService {
HttpStatus.NOT_FOUND
);
}

const customFields = cohortMembersUpdateDto.customFields;
delete cohortMembersUpdateDto.customFields;
Object.assign(cohortMembershipToUpdate, cohortMembersUpdateDto);

await this.cohortMembersRepository.save(cohortMembershipToUpdate);
//update custom fields

let responseForCustomField = await this.processCustomFields(
customFields,
cohortMembershipId,
cohortMembersUpdateDto
let result = await this.cohortMembersRepository.save(
cohortMembershipToUpdate
);
if (responseForCustomField.success) {
//update custom fields
let responseForCustomField;
if (
cohortMembersUpdateDto.customFields &&
cohortMembersUpdateDto.customFields.length > 0
) {
const customFields = cohortMembersUpdateDto.customFields;
delete cohortMembersUpdateDto.customFields;
Object.assign(cohortMembershipToUpdate, cohortMembersUpdateDto);

responseForCustomField = await this.processCustomFields(
customFields,
cohortMembershipId,
cohortMembersUpdateDto
);
if (result && responseForCustomField.success) {
return APIResponse.success(
res,
apiId,
[],
HttpStatus.CREATED,
API_RESPONSES.COHORTMEMBER_UPDATE_SUCCESSFULLY
);
} else {
const errorMessage =
responseForCustomField.error || "Internal server error";
return APIResponse.error(
res,
apiId,
"Internal Server Error",
errorMessage,
HttpStatus.INTERNAL_SERVER_ERROR
);
}
}
if (result) {
return APIResponse.success(
res,
apiId,
Expand Down

0 comments on commit a3c4fcf

Please sign in to comment.