package.cjs.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":["_neetoCist","require","_ramda","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","buildNestedAttributesPayload","_ref","modifiedValues","initialValues","nestedKeyToModify","nestedAttributeKeyInPayload","nestedAttributesForArrayKey","itemsToDestroy","initialItem","isNotPresent","findBy","value","itemsToDestroyAttrs","map","item","_ref2","id","itemsToBeCreated","modifiedItem","toLowerCase","itemsToCreateAttrs","nestedAttributes","concat","_toConsumableArray2","omit","exports"],"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,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAA6B,SAAAE,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,IAAA,EAAAG,OAAA,YAAAH,IAAA;AAAA,SAAAU,cAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,WAAAF,SAAA,CAAAD,CAAA,IAAAC,SAAA,CAAAD,CAAA,QAAAA,CAAA,OAAAf,OAAA,CAAAI,MAAA,CAAAc,MAAA,OAAAC,OAAA,WAAAC,GAAA,QAAAC,gBAAA,aAAAP,MAAA,EAAAM,GAAA,EAAAF,MAAA,CAAAE,GAAA,SAAAhB,MAAA,CAAAkB,yBAAA,GAAAlB,MAAA,CAAAmB,gBAAA,CAAAT,MAAA,EAAAV,MAAA,CAAAkB,yBAAA,CAAAJ,MAAA,KAAAlB,OAAA,CAAAI,MAAA,CAAAc,MAAA,GAAAC,OAAA,WAAAC,GAAA,IAAAhB,MAAA,CAAAoB,cAAA,CAAAV,MAAA,EAAAM,GAAA,EAAAhB,MAAA,CAAAK,wBAAA,CAAAS,MAAA,EAAAE,GAAA,iBAAAN,MAAA;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