package.utils.buildNestedAttributesPayload.js.map Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of neeto-commons-frontend Show documentation
Show all versions of neeto-commons-frontend Show documentation
A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.
{"version":3,"file":"buildNestedAttributesPayload.js","names":["findBy","isNotPresent","omit","buildNestedAttributesPayload","_ref","modifiedValues","initialValues","nestedKeyToModify","nestedAttributeKeyInPayload","nestedAttributesForArrayKey","itemsToDestroy","filter","initialItem","value","itemsToDestroyAttrs","map","item","_ref2","id","_defineProperty","itemsToBeCreated","modifiedItem","toLowerCase","itemsToCreateAttrs","nestedAttributes","concat","_toConsumableArray","_objectSpread"],"sources":["../../src/utils/buildNestedAttributesPayload.js"],"sourcesContent":["import { findBy, isNotPresent } from \"neetocist\";\nimport { omit } from \"ramda\";\n\nexport const buildNestedAttributesPayload = ({\n modifiedValues,\n initialValues,\n nestedKeyToModify,\n nestedAttributeKeyInPayload,\n nestedAttributesForArrayKey,\n}) => {\n const itemsToDestroy = initialValues[nestedKeyToModify].filter(initialItem =>\n isNotPresent(\n findBy(\n { value: initialItem[nestedAttributeKeyInPayload] },\n modifiedValues[nestedKeyToModify]\n )\n )\n );\n\n const itemsToDestroyAttrs = itemsToDestroy.map(item => ({\n id: item.id,\n [nestedAttributeKeyInPayload]: item[nestedAttributeKeyInPayload],\n _destroy: true,\n }));\n\n const itemsToBeCreated = modifiedValues[nestedKeyToModify].filter(\n modifiedItem =>\n isNotPresent(\n findBy(\n { [nestedAttributeKeyInPayload]: modifiedItem.value.toLowerCase() },\n initialValues[nestedKeyToModify]\n )\n )\n );\n\n const itemsToCreateAttrs = itemsToBeCreated.map(item => ({\n [nestedAttributeKeyInPayload]: item.value,\n }));\n\n const nestedAttributes = [...itemsToCreateAttrs, ...itemsToDestroyAttrs];\n\n return {\n ...omit([nestedKeyToModify], modifiedValues),\n [nestedAttributesForArrayKey]: nestedAttributes,\n };\n};\n"],"mappings":";;;;AAAA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