Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/appmixer/hubspot/commons.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {

WATCHED_PROPERTIES_CONTACT: ['email', 'firstname', 'lastname', 'phone', 'website', 'company', 'address', 'city', 'state', 'zip'],
WATCHED_PROPERTIES_DEAL: ['dealname', 'dealstage', 'pipeline', 'hubSpotOwnerId', 'closedate', 'amount'],
WATCHED_PROPERTIES_COMPANY: ['name', 'domain', 'industry', 'website', 'phone', 'city', 'state', 'country', 'description', 'hubspot_owner_id'],

async getObjectProperties(context, hubspot, objectType, output = 'all') {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
'use strict';

const Hubspot = require('../../Hubspot');
const { getObjectProperties, WATCHED_PROPERTIES_COMPANY } = require('../../commons');

module.exports = {

async receive(context) {

const { auth } = context;
const hs = new Hubspot(auth.accessToken, context.config);
const properties = await getObjectProperties(context, hs, 'companies', 'all');

const propertiesToOutput = context.messages.in.content?.properties;
if (propertiesToOutput) {
// We have a set of properties defined in the inspector.
// We only want to return these properties. See GetCompany/component.json - outPorts
const propertiesToReturn = properties.filter((property) => propertiesToOutput.includes(property.name));

return context.sendJson(propertiesToReturn, 'out');
}

return context.sendJson(properties, 'out');
},

/** Returns properties that are not hardcoded into the component. Both custom and HubSpot properties. */
additionalFieldsToSelectArray(companiesProperties) {

return companiesProperties
.filter((property) => !WATCHED_PROPERTIES_COMPANY.includes(property.name))
.map((property) => {
return { label: property.label, value: property.name };
});
},

companiesPropertiesToCompanyInspector(companiesProperties) {

let inspector = {
inputs: {
companiesProperties: {}
}
};
if (Array.isArray(companiesProperties)) {
let index = 1;
companiesProperties.forEach((property) => {
if (!property.hidden) {

let field = {
type: 'text',
label: property.label || property.name,
index: index++
};

switch (property.type) {
case 'string':
field.type = property.fieldType === 'textarea' ? 'textarea' : 'text';
break;
case 'number':
field.type = 'number';
break;
case 'phone_number':
field.type = 'text';
break;
case 'datetime':
field.type = 'date-time';
break;
case 'date':
field.type = 'date-time';
break;
case 'bool':
field.type = 'toggle';
break;
case 'enumeration':
field.type = 'select';
field.options = (property.options || []).map((option) => {
return { content: option.label, value: option.value };
});
break;
}
inspector.inputs.companiesProperties[property.name] = field;
}
});
}

return inspector;
}
};

Check failure on line 87 in src/appmixer/hubspot/crm/GetCompaniesProperties/GetCompaniesProperties.js

View workflow job for this annotation

GitHub Actions / build

Newline required at end of file but not found
Loading