JSFiddle - React, Tailwind, and code Playground

by bilbobaggins

HTML

991241788 1336
991241935  550
933356027

JavaScript

let validationmap = [
  {
    inputtype: 'multiselect',
    inputname: 'roleid',
    inputtextval: 'rolename',
    inputCustomMapping: 'rolename',
    inputParent: 'role',
    inputplaceholder: 'Rolename',
    selecttype: 'single',
    fieldtypename: 'STRING',
    fieldvalidatename: 'number',
    fieldmaxlength: '80'
  },
  {
    inputtype: 'multiselect',
    inputname: 'modnameid',
    inputtextval: 'mname',
    selecttype: 'multi',
    inputCustomMapping: 'modulename',
    inputParent: 'modname',
    inputplaceholder: 'Module',
    fieldtypename: 'STRING',
    fieldvalidatename: 'number',
    fieldmaxlength: '80'
  },
  {
    inputtype: 'multiselect',
    inputtextval: 'accesstype',
    inputname: 'accesstype',
    inputCustomMapping: 'accesstype',
    inputplaceholder: 'accesstype',
    fieldtypename: 'STRING',
    fieldvalidatename: 'string',
    fieldmaxlength: '2',
    childcontent: [{
      val: "VO",
      text: "ViewOnly"
    },
    {
      val: "AA",
      text: "AllAccess"
    }
  ]

  }
]
let w=0
let coltype=""
let searchparam=[ { roleid: [ '1' ] }, { modnameid: [ '28', '29' ] } ]
const allowedColumns = new Set(
  validationmap.map(item => item.inputname)
  );
 console.log((allowedColumns))
 // console.log(validationmap.map(item => item.inputname))



  const startParam = w === 4 ? 3 : 2;

  let redlime= Object.values(searchparam)
    .flatMap(obj => Object.keys(obj))
    .filter(column => allowedColumns.has(column))
    .map((column, index) => {
      const paramNumber = startParam + index + 1;

      return ` and ${coltype}(a."${column}") = ANY($${paramNumber})`;
    })
    .join("");

    //console.log(redlime)
console.log(Object.values(searchparam)
    .flatMap(obj => Object.keys(obj)))