fixed zapier removeKeyPrefixes method (#16305)

This commit is contained in:
Emanuele Saccomandi
2023-08-11 13:09:54 +02:00
committed by GitHub
parent 2635b52b42
commit 8f9e6432f5
4 changed files with 4 additions and 4 deletions

View File

@@ -83,7 +83,7 @@ module.exports = {
const {keyPrefix} = utils.buildKeyAndLabel(prefix)
return {
{{#vars}}
'{{baseName}}': {{#isPrimitiveType}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/isPrimitiveType}}{{^isPrimitiveType}}{{^allowableValues}}{{^isArray}}utils.removeIfEmpty({{complexType}}.mapping(bundle, `${keyPrefix}{{baseName}}`)){{/isArray}}{{#isArray}}utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}{{baseName}}`]){{/isArray}}{{/allowableValues}}{{#allowableValues}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/allowableValues}}{{/isPrimitiveType}},
'{{baseName}}': {{#isPrimitiveType}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/isPrimitiveType}}{{^isPrimitiveType}}{{^allowableValues}}{{^isArray}}utils.removeIfEmpty({{complexType}}.mapping(bundle, `${keyPrefix}{{baseName}}`)){{/isArray}}{{#isArray}}utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}{{baseName}}`], `${keyPrefix}{{baseName}}`){{/isArray}}{{/allowableValues}}{{#allowableValues}}bundle.inputData?.[`${keyPrefix}{{baseName}}`]{{/allowableValues}}{{/isPrimitiveType}},
{{/vars}}
}
},

View File

@@ -1,7 +1,7 @@
const _ = require('lodash')
const replacePathParameters = (url) => url.replace(/{([^{}]+)}/g, (keyExpr, key) => `{{bundle.inputData.${key}}}`)
const removeKeyPrefixes = (objectsArray) => objectsArray == undefined || typeof objectsArray[0] != 'object' ? objectsArray : objectsArray.map((obj) => Object.keys(obj).reduce((res, key) => (res[(key.split('.')).slice(-1)] = obj[key], res), {}))
const removeKeyPrefixes = (objectsArray, currentPath) => objectsArray == undefined || typeof objectsArray[0] != 'object' ? objectsArray : objectsArray.map((obj) => Object.keys(obj).reduce((res, key) =>_.set(res, key.replace(`${currentPath}.`, ''), obj[key]), {}))
const removeIfEmpty = (obj) => _.isEmpty(JSON.parse(JSON.stringify(obj))) ? undefined : obj
const buildKeyAndLabel = (prefix, isInput = true, isArrayChild = false) => {
const keyPrefix = !_.isEmpty(prefix) && (!isArrayChild || isInput) ? `${prefix}${isInput ? '.' : '__'}` : prefix

View File

@@ -47,7 +47,7 @@ module.exports = {
'category': utils.removeIfEmpty(Category.mapping(bundle, `${keyPrefix}category`)),
'name': bundle.inputData?.[`${keyPrefix}name`],
'photoUrls': bundle.inputData?.[`${keyPrefix}photoUrls`],
'tags': utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}tags`]),
'tags': utils.removeKeyPrefixes(bundle.inputData?.[`${keyPrefix}tags`], `${keyPrefix}tags`),
'status': bundle.inputData?.[`${keyPrefix}status`],
}
},

View File

@@ -1,7 +1,7 @@
const _ = require('lodash')
const replacePathParameters = (url) => url.replace(/{([^{}]+)}/g, (keyExpr, key) => `{{bundle.inputData.${key}}}`)
const removeKeyPrefixes = (objectsArray) => objectsArray == undefined || typeof objectsArray[0] != 'object' ? objectsArray : objectsArray.map((obj) => Object.keys(obj).reduce((res, key) => (res[(key.split('.')).slice(-1)] = obj[key], res), {}))
const removeKeyPrefixes = (objectsArray, currentPath) => objectsArray == undefined || typeof objectsArray[0] != 'object' ? objectsArray : objectsArray.map((obj) => Object.keys(obj).reduce((res, key) =>_.set(res, key.replace(`${currentPath}.`, ''), obj[key]), {}))
const removeIfEmpty = (obj) => _.isEmpty(JSON.parse(JSON.stringify(obj))) ? undefined : obj
const buildKeyAndLabel = (prefix, isInput = true, isArrayChild = false) => {
const keyPrefix = !_.isEmpty(prefix) && (!isArrayChild || isInput) ? `${prefix}${isInput ? '.' : '__'}` : prefix