Skip to content

Commit

Permalink
feature/mautic-extended
Browse files Browse the repository at this point in the history
  • Loading branch information
RicardoE105 committed Jan 6, 2021
1 parent 57e19ed commit 1fe1744
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
72 changes: 72 additions & 0 deletions packages/nodes-base/nodes/Mautic/ContactDescription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,42 @@ export const contactFields = [
type: 'string',
default: '',
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Fields',
description: 'Adds a custom fields to set also values which have not been predefined.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'customFieldValues',
displayName: 'Field',
values: [
{
displayName: 'Field ID',
name: 'fieldId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContactFields',
},
default: '',
description: 'ID of the field to set.',
},
{
displayName: 'Field Value',
name: 'fieldValue',
type: 'string',
default: '',
description: 'Value of the field to set.',
},
],
},
],
},
{
displayName: 'Fax',
name: 'fax',
Expand Down Expand Up @@ -617,6 +653,42 @@ export const contactFields = [
},
default: '',
},
{
displayName: 'Custom Fields',
name: 'customFieldsUi',
placeholder: 'Add Custom Fields',
description: 'Adds a custom fields to set also values which have not been predefined.',
type: 'fixedCollection',
typeOptions: {
multipleValues: true,
},
default: {},
options: [
{
name: 'customFieldValues',
displayName: 'Field',
values: [
{
displayName: 'Field ID',
name: 'fieldId',
type: 'options',
typeOptions: {
loadOptionsMethod: 'getContactFields',
},
default: '',
description: 'ID of the field to set.',
},
{
displayName: 'Field Value',
name: 'fieldValue',
type: 'string',
default: '',
description: 'Value of the field to set.',
},
],
},
],
},
{
displayName: 'Email',
name: 'email',
Expand Down
27 changes: 27 additions & 0 deletions packages/nodes-base/nodes/Mautic/Mautic.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ export class Mautic implements INodeType {
}
return returnData;
},
// Get all the available contact fields to display them to user so that he can
// select them easily
async getContactFields(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const fields = await mauticApiRequestAllItems.call(this, 'fields', 'GET', '/fields/contact');
for (const field of fields) {
returnData.push({
name: field.label,
value: field.alias,
});
}
return returnData;
},
},
};

Expand Down Expand Up @@ -327,6 +340,13 @@ export class Mautic implements INodeType {
body.twitter = socialMediaValues.twitter as string;
}
}
if (additionalFields.customFieldsUi) {
const customFields = (additionalFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
if (customFields) {
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
Object.assign(body, data);
}
}
if (additionalFields.b2bOrb2c) {
body.b2b_or_b2c = additionalFields.b2bOrb2c as string;
}
Expand Down Expand Up @@ -429,6 +449,13 @@ export class Mautic implements INodeType {
body.twitter = socialMediaValues.twitter as string;
}
}
if (updateFields.customFieldsUi) {
const customFields = (updateFields.customFieldsUi as IDataObject).customFieldValues as IDataObject[];
if (customFields) {
const data = customFields.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
Object.assign(body, data);
}
}
if (updateFields.b2bOrb2c) {
body.b2b_or_b2c = updateFields.b2bOrb2c as string;
}
Expand Down

0 comments on commit 1fe1744

Please sign in to comment.