I have two objects below,
let response = {
offer: {
custom_fields: {
job_title: 'engineer'
},
starts_at: 'test',
job_post: 'test'
}
}
let defaultFieldMapping = {
"$.engagementData.title": {
default: "Software Engineer",
path: "$.offer.custom_fields.job_title",
fieldName: 'Title'
},
"$.engagementData.startDateUTC": {
default: null,
path: "$.offer.starts_at",
},
}
Need to form new object and expected result like below
let expectedResult = [
{
externalFieldId: '$.offer.custom_fields.job_title',
integrationFieldId: '$.engagementData.title'
},
{
externalFieldId: '$.offer.starts_at',
integrationFieldId: '$.engagementData.startDateUTC'
},
{
externalFieldId: '$.offer.job_post',
integrationFieldId: ''
},
]
integrationFieldId is empty string because that’s not exists in the defaultFieldMapping path column.
2
Answers
Your code does not include any type information and is therefore just Java Script which is underlying to to Type Script. From your example it is not clear where the third entry is coming from but for the first two, you could simply write a function that returns the new object:
(Disclaimer: This code is untested.)