Skip to content

Commit

Permalink
Merge pull request #183 from Shubham4026/sdbv_field_changes
Browse files Browse the repository at this point in the history
Sdbv field changes
  • Loading branch information
Shubham4026 authored Mar 7, 2025
2 parents f03c22d + a73a97f commit 518b85a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/adapters/postgres/cohort-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ export class PostgresCohortService {
) {
const validationResponse = await this.fieldsService.validateCustomField(
cohortCreateDto,
cohortCreateDto.type
"COHORT"
);

// Check the validation response
Expand Down
8 changes: 4 additions & 4 deletions src/adapters/postgres/fields-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import jwt_decode from "jwt-decode";
import { LoggerUtil } from "src/common/logger/LoggerUtil";
import { API_RESPONSES } from "@utils/response.messages";
import { FieldValuesDeleteDto } from "src/fields/dto/field-values-delete.dto";
import { check } from "prettier";
@Injectable()
export class PostgresFieldsService implements IServicelocatorfields {
constructor(
Expand Down Expand Up @@ -117,6 +118,7 @@ export class PostgresFieldsService implements IServicelocatorfields {

//validate cohort Create/update API Custom field
public async validateCustomField(cohortCreateDto, contextType) {
const tenantId = cohortCreateDto?.tenantId;
const fieldValues = cohortCreateDto ? cohortCreateDto.customFields : [];
const encounteredKeys = [];
const invalidateFields = [];
Expand All @@ -139,7 +141,8 @@ export class PostgresFieldsService implements IServicelocatorfields {
} else {
encounteredKeys.push(fieldId);
}

const fieldAttributes = getFieldDetails?.fieldAttributes || {};
getFieldDetails["fieldAttributes"] = fieldAttributes[tenantId] || fieldAttributes["default"];
if (
(getFieldDetails.type == "checkbox" ||
getFieldDetails.type == "drop_down" ||
Expand Down Expand Up @@ -172,7 +175,6 @@ export class PostgresFieldsService implements IServicelocatorfields {
getFieldDetails,
fieldsData["value"]
);

if (typeof checkValidation === "object" && "error" in checkValidation) {
invalidateFields.push(
`${fieldId}: ${getFieldDetails["name"]} - ${checkValidation?.error?.message}`
Expand All @@ -197,9 +199,7 @@ export class PostgresFieldsService implements IServicelocatorfields {
}
const context = "COHORT";
const getFieldIds = await this.getFieldIds(context, contextType);

const validFieldIds = new Set(getFieldIds.map((field) => field.fieldId));

const invalidFieldIds = cohortCreateDto.customFields
.filter((fieldValue) => !validFieldIds.has(fieldValue.fieldId))
.map((fieldValue) => fieldValue.fieldId);
Expand Down
6 changes: 3 additions & 3 deletions src/fields/fieldValidators/field.util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConsoleLogger } from "@nestjs/common";

export function validateMultiSelect(value, fieldDetails) {
const fieldParamsOptions = fieldDetails.fieldParams.options.map(
({ value }) => value
);
// const fieldParamsOptions = fieldDetails?.fieldParams?.options.map(
// ({ value }) => value
// );
if (fieldDetails.fieldAttributes.isMultiSelect) {
if (!Array.isArray(value)) {
throw new Error("Value must be an array for multiple selections.");
Expand Down

0 comments on commit 518b85a

Please sign in to comment.