mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Add more parameters to company resource (Mautic) (#2087)
* Add Json params on company * Revert and add only JSON params on Company * Fix Company search field * ⚡ Improvements to #1957 * ⚡ Improvements Co-authored-by: Dokime <jnau5@yahoo.com>
This commit is contained in:
@@ -193,6 +193,21 @@ export class Mautic implements INodeType {
|
||||
}
|
||||
return returnData;
|
||||
},
|
||||
async getIndustries(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
|
||||
const returnData: INodePropertyOptions[] = [];
|
||||
const fields = await mauticApiRequestAllItems.call(this, 'fields', 'GET', '/fields/company');
|
||||
for (const field of fields) {
|
||||
if (field.alias === 'companyindustry') {
|
||||
for (const { label, value } of field.properties.list) {
|
||||
returnData.push({
|
||||
name: label,
|
||||
value,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
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[]> {
|
||||
@@ -235,16 +250,101 @@ export class Mautic implements INodeType {
|
||||
for (let i = 0; i < length; i++) {
|
||||
qs = {};
|
||||
try {
|
||||
|
||||
if (resource === 'company') {
|
||||
//https://developer.mautic.org/#create-company
|
||||
if (operation === 'create') {
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const simple = this.getNodeParameter('simple', i) as boolean;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
const name = this.getNodeParameter('name', i) as string;
|
||||
const body: IDataObject = {
|
||||
companyname: name,
|
||||
};
|
||||
Object.assign(body, additionalFields);
|
||||
const {
|
||||
addressUi,
|
||||
customFieldsUi,
|
||||
companyEmail,
|
||||
fax,
|
||||
industry,
|
||||
numberOfEmpoyees,
|
||||
phone,
|
||||
website,
|
||||
annualRevenue,
|
||||
description,
|
||||
...rest
|
||||
} = this.getNodeParameter('additionalFields', i) as {
|
||||
addressUi: {
|
||||
addressValues: IDataObject,
|
||||
},
|
||||
customFieldsUi: {
|
||||
customFieldValues: [
|
||||
{
|
||||
fieldId: string,
|
||||
fieldValue: string,
|
||||
},
|
||||
],
|
||||
}
|
||||
companyEmail: string,
|
||||
fax: string,
|
||||
industry: string,
|
||||
numberOfEmpoyees: number,
|
||||
phone: string,
|
||||
website: string,
|
||||
annualRevenue: number,
|
||||
description: string,
|
||||
};
|
||||
if (addressUi?.addressValues) {
|
||||
const { addressValues } = addressUi;
|
||||
body.companyaddress1 = addressValues.address1 as string;
|
||||
body.companyaddress2 = addressValues.address2 as string;
|
||||
body.companycity = addressValues.city as string;
|
||||
body.companystate = addressValues.state as string;
|
||||
body.companycountry = addressValues.country as string;
|
||||
body.companyzipcode = addressValues.zipCode as string;
|
||||
}
|
||||
|
||||
if (companyEmail) {
|
||||
body.companyemail = companyEmail;
|
||||
}
|
||||
|
||||
if (fax) {
|
||||
body.companyfax = fax;
|
||||
}
|
||||
|
||||
if (industry) {
|
||||
body.companyindustry = industry;
|
||||
}
|
||||
|
||||
if (industry) {
|
||||
body.companyindustry = industry;
|
||||
}
|
||||
|
||||
if (numberOfEmpoyees) {
|
||||
body.companynumber_of_employees = numberOfEmpoyees;
|
||||
}
|
||||
|
||||
if (phone) {
|
||||
body.companyphone = phone;
|
||||
}
|
||||
|
||||
if (website) {
|
||||
body.companywebsite = website;
|
||||
}
|
||||
|
||||
if (annualRevenue) {
|
||||
body.companyannual_revenue = annualRevenue;
|
||||
}
|
||||
|
||||
if (description) {
|
||||
body.companydescription = description;
|
||||
}
|
||||
|
||||
if (customFieldsUi?.customFieldValues) {
|
||||
const { customFieldValues } = customFieldsUi;
|
||||
const data = customFieldValues.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
|
||||
Object.assign(body, data);
|
||||
}
|
||||
|
||||
Object.assign(body, rest);
|
||||
responseData = await mauticApiRequest.call(this, 'POST', '/companies/new', body);
|
||||
responseData = responseData.company;
|
||||
if (simple === true) {
|
||||
@@ -255,13 +355,100 @@ export class Mautic implements INodeType {
|
||||
if (operation === 'update') {
|
||||
const companyId = this.getNodeParameter('companyId', i) as string;
|
||||
const simple = this.getNodeParameter('simple', i) as boolean;
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
const body: IDataObject = {};
|
||||
Object.assign(body, updateFields);
|
||||
if (body.name) {
|
||||
body.companyname = body.name;
|
||||
delete body.name;
|
||||
const {
|
||||
addressUi,
|
||||
customFieldsUi,
|
||||
companyEmail,
|
||||
name,
|
||||
fax,
|
||||
industry,
|
||||
numberOfEmpoyees,
|
||||
phone,
|
||||
website,
|
||||
annualRevenue,
|
||||
description,
|
||||
...rest
|
||||
} = this.getNodeParameter('updateFields', i) as {
|
||||
addressUi: {
|
||||
addressValues: IDataObject,
|
||||
},
|
||||
customFieldsUi: {
|
||||
customFieldValues: [
|
||||
{
|
||||
fieldId: string,
|
||||
fieldValue: string,
|
||||
},
|
||||
],
|
||||
}
|
||||
companyEmail: string,
|
||||
name: string,
|
||||
fax: string,
|
||||
industry: string,
|
||||
numberOfEmpoyees: number,
|
||||
phone: string,
|
||||
website: string,
|
||||
annualRevenue: number,
|
||||
description: string,
|
||||
};
|
||||
if (addressUi?.addressValues) {
|
||||
const { addressValues } = addressUi;
|
||||
body.companyaddress1 = addressValues.address1 as string;
|
||||
body.companyaddress2 = addressValues.address2 as string;
|
||||
body.companycity = addressValues.city as string;
|
||||
body.companystate = addressValues.state as string;
|
||||
body.companycountry = addressValues.country as string;
|
||||
body.companyzipcode = addressValues.zipCode as string;
|
||||
}
|
||||
|
||||
if (companyEmail) {
|
||||
body.companyemail = companyEmail;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
body.companyname = name;
|
||||
}
|
||||
|
||||
if (fax) {
|
||||
body.companyfax = fax;
|
||||
}
|
||||
|
||||
if (industry) {
|
||||
body.companyindustry = industry;
|
||||
}
|
||||
|
||||
if (industry) {
|
||||
body.companyindustry = industry;
|
||||
}
|
||||
|
||||
if (numberOfEmpoyees) {
|
||||
body.companynumber_of_employees = numberOfEmpoyees;
|
||||
}
|
||||
|
||||
if (phone) {
|
||||
body.companyphone = phone;
|
||||
}
|
||||
|
||||
if (website) {
|
||||
body.companywebsite = website;
|
||||
}
|
||||
|
||||
if (annualRevenue) {
|
||||
body.companyannual_revenue = annualRevenue;
|
||||
}
|
||||
|
||||
if (description) {
|
||||
body.companydescription = description;
|
||||
}
|
||||
|
||||
if (customFieldsUi?.customFieldValues) {
|
||||
const { customFieldValues } = customFieldsUi;
|
||||
const data = customFieldValues.reduce((obj, value) => Object.assign(obj, { [`${value.fieldId}`]: value.fieldValue }), {});
|
||||
Object.assign(body, data);
|
||||
}
|
||||
|
||||
Object.assign(body, rest);
|
||||
|
||||
responseData = await mauticApiRequest.call(this, 'PATCH', `/companies/${companyId}/edit`, body);
|
||||
responseData = responseData.company;
|
||||
if (simple === true) {
|
||||
|
||||
Reference in New Issue
Block a user