mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-19 11:01:15 +00:00
⚡ Add full continue-on-fail support to all nodes (#1996)
* Update Compression node * Update Crypto node * Update DateTime node * Update EditImage node * Update EmailSend node * Update ExecuteWorkflow node * Update FTP node * Update Function node * Update FunctionItem node * Update ExecuteCommand node * Update OpenWeatherMap node * Update ReadBinaryFile node * Update ReadPdf node * Update RssFeedRead node & add URL validation * Update SpreadsheetFile node * Update Switch node * Update WriteBinaryFile node * Update Xml node * Update ActiveCampaign node * Update Airtable node * Update ApiTemplateIo node * Update Asana node * Update AwsLambda node * Update AwsSns node * Update AwsComprehend node * Update AwsRekognition node * Update AwsS3 node * Fix Error item * Update AwsSes node * Update AwsSqs node * Update Amqp node * Update Bitly node * Update Box node * Update Brandfetch node * Update CircleCi node * Update Clearbit node * Update ClickUp node * Update Cockpit node * Update CoinGecko node * Update Contentful node * Update ConvertKit node * Update Cortex node * Update CustomerIo node * Update DeepL node * Update Demio node * Update Disqus node * Update Drift node * Update Dropbox node * Update GetResponse node * Refactor & Update Ghost node * Update Github node * Update Gitlab node * Update GoogleAnalytics node * Update GoogleBooks node * Update GoogleCalendar node * Update GoogleDrive node * Update Gmail node * Update GoogleSheets node * Update GoogleSlides node * Update GoogleTasks node * Update Gotify node * Update GraphQL node * Update HackerNews node * Update Harvest node * Update HtmlExtract node * Update Hubspot node * Update Hunter node * Update Intercom node * Update Kafka node * Refactor & update Line node * Update LinkedIn node * Update Mailchimp node * Update Mandrill node * Update Matrix node * Update Mautic node * Update Medium node * Update MessageBird node * Update Mindee node * Update Mocean node * Update MondayCom node * Update MicrosoftExcel node * Update MicrosoftOneDrive node * Update MicrosoftOutlook node * Update Affinity node * Update Chargebee node * Update Discourse node * Update Freshdesk node * Update YouTube node * Update InvoiceNinja node * Update MailerLite node * Update Mailgun node * Update Mailjet node * Update Mattermost node * Update Nasa node * Update NextCloud node * Update OpenThesaurus node * Update Orbit node * Update PagerDuty node * Update PayPal node * Update Peekalink node * Update Phantombuster node * Update PostHog node * Update ProfitWell node * Refactor & Update Pushbullet node * Update QuickBooks node * Update Raindrop node * Update Reddit node * Update Rocketchat node * Update S3 node * Update Salesforce node * Update SendGrid node * Update SentryIo node * Update Shopify node * Update Signl4 node * Update Slack node * Update Spontit node * Update Spotify node * Update Storyblok node * Refactor & Update Strapi node * Refactor & Update Strava node * Update Taiga node * Refactor & update Tapfiliate node * Update Telegram node * Update TheHive node * Update Todoist node * Update TravisCi node * Update Trello node * Update Twilio node * Update Twist node * Update Twitter node * Update Uplead node * Update UProc node * Update Vero node * Update Webflow node * Update Wekan node * Update Wordpress node * Update Xero node * Update Yourls node * Update Zendesk node * Update ZohoCrm node * Refactor & Update Zoom node * Update Zulip node * Update Clockify node * Update MongoDb node * Update MySql node * Update MicrosoftTeams node * Update Stackby node * Refactor Discourse node * Support corner-case in Github node update * Support corner-case in Gitlab node update * Refactor & Update GoogleContacts node * Refactor Mindee node * Update Coda node * Lint fixes * Update Beeminder node * Update Google Firebase RealtimeDatabase node * Update HelpScout node * Update Mailcheck node * Update Paddle node * Update Pipedrive node * Update Pushover node * Update Segment node * Refactor & Update Vonage node * Added new conditions to warnings on execute batch cmd * Added keep only properties flag * Fixed code for keep only props * Added dependencies for image editing Co-authored-by: dali <servfrdali@yahoo.fr>
This commit is contained in:
@@ -101,396 +101,404 @@ export class GoogleContacts implements INodeType {
|
||||
const resource = this.getNodeParameter('resource', 0) as string;
|
||||
const operation = this.getNodeParameter('operation', 0) as string;
|
||||
for (let i = 0; i < length; i++) {
|
||||
if (resource === 'contact') {
|
||||
//https://developers.google.com/calendar/v3/reference/events/insert
|
||||
if (operation === 'create') {
|
||||
const familyName = this.getNodeParameter('familyName', i) as string;
|
||||
const givenName = this.getNodeParameter('givenName', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
try {
|
||||
if (resource === 'contact') {
|
||||
//https://developers.google.com/calendar/v3/reference/events/insert
|
||||
if (operation === 'create') {
|
||||
const familyName = this.getNodeParameter('familyName', i) as string;
|
||||
const givenName = this.getNodeParameter('givenName', i) as string;
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
const body: IDataObject = {
|
||||
names: [
|
||||
{
|
||||
familyName,
|
||||
givenName,
|
||||
middleName: '',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
if (additionalFields.middleName) {
|
||||
//@ts-ignore
|
||||
body.names[0].middleName = additionalFields.middleName as string;
|
||||
}
|
||||
|
||||
if (additionalFields.honorificPrefix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificPrefix = additionalFields.honorificPrefix as string;
|
||||
}
|
||||
|
||||
if (additionalFields.honorificSuffix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificSuffix = additionalFields.honorificSuffix as string;
|
||||
}
|
||||
|
||||
if (additionalFields.companyUi) {
|
||||
const companyValues = (additionalFields.companyUi as IDataObject).companyValues as IDataObject[];
|
||||
body.organizations = companyValues;
|
||||
}
|
||||
|
||||
if (additionalFields.phoneUi) {
|
||||
const phoneValues = (additionalFields.phoneUi as IDataObject).phoneValues as IDataObject[];
|
||||
body.phoneNumbers = phoneValues;
|
||||
}
|
||||
|
||||
if (additionalFields.addressesUi) {
|
||||
const addressesValues = (additionalFields.addressesUi as IDataObject).addressesValues as IDataObject[];
|
||||
body.addresses = addressesValues;
|
||||
}
|
||||
|
||||
if (additionalFields.relationsUi) {
|
||||
const relationsValues = (additionalFields.relationsUi as IDataObject).relationsValues as IDataObject[];
|
||||
body.relations = relationsValues;
|
||||
}
|
||||
|
||||
if (additionalFields.eventsUi) {
|
||||
const eventsValues = (additionalFields.eventsUi as IDataObject).eventsValues as IDataObject[];
|
||||
for (let i = 0; i < eventsValues.length; i++) {
|
||||
const [month, day, year] = moment(eventsValues[i].date as string).format('MM/DD/YYYY').split('/');
|
||||
eventsValues[i] = {
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
const body: IDataObject = {
|
||||
names: [
|
||||
{
|
||||
familyName,
|
||||
givenName,
|
||||
middleName: '',
|
||||
},
|
||||
type: eventsValues[i].type,
|
||||
};
|
||||
],
|
||||
};
|
||||
|
||||
if (additionalFields.middleName) {
|
||||
//@ts-ignore
|
||||
body.names[0].middleName = additionalFields.middleName as string;
|
||||
}
|
||||
body.events = eventsValues;
|
||||
}
|
||||
|
||||
if (additionalFields.birthday) {
|
||||
const [month, day, year] = moment(additionalFields.birthday as string).format('MM/DD/YYYY').split('/');
|
||||
if (additionalFields.honorificPrefix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificPrefix = additionalFields.honorificPrefix as string;
|
||||
}
|
||||
|
||||
body.birthdays = [
|
||||
{
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
if (additionalFields.honorificSuffix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificSuffix = additionalFields.honorificSuffix as string;
|
||||
}
|
||||
|
||||
if (additionalFields.companyUi) {
|
||||
const companyValues = (additionalFields.companyUi as IDataObject).companyValues as IDataObject[];
|
||||
body.organizations = companyValues;
|
||||
}
|
||||
|
||||
if (additionalFields.phoneUi) {
|
||||
const phoneValues = (additionalFields.phoneUi as IDataObject).phoneValues as IDataObject[];
|
||||
body.phoneNumbers = phoneValues;
|
||||
}
|
||||
|
||||
if (additionalFields.addressesUi) {
|
||||
const addressesValues = (additionalFields.addressesUi as IDataObject).addressesValues as IDataObject[];
|
||||
body.addresses = addressesValues;
|
||||
}
|
||||
|
||||
if (additionalFields.relationsUi) {
|
||||
const relationsValues = (additionalFields.relationsUi as IDataObject).relationsValues as IDataObject[];
|
||||
body.relations = relationsValues;
|
||||
}
|
||||
|
||||
if (additionalFields.eventsUi) {
|
||||
const eventsValues = (additionalFields.eventsUi as IDataObject).eventsValues as IDataObject[];
|
||||
for (let i = 0; i < eventsValues.length; i++) {
|
||||
const [month, day, year] = moment(eventsValues[i].date as string).format('MM/DD/YYYY').split('/');
|
||||
eventsValues[i] = {
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
},
|
||||
type: eventsValues[i].type,
|
||||
};
|
||||
}
|
||||
body.events = eventsValues;
|
||||
}
|
||||
|
||||
if (additionalFields.birthday) {
|
||||
const [month, day, year] = moment(additionalFields.birthday as string).format('MM/DD/YYYY').split('/');
|
||||
|
||||
body.birthdays = [
|
||||
{
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
if (additionalFields.emailsUi) {
|
||||
const emailsValues = (additionalFields.emailsUi as IDataObject).emailsValues as IDataObject[];
|
||||
body.emailAddresses = emailsValues;
|
||||
}
|
||||
if (additionalFields.emailsUi) {
|
||||
const emailsValues = (additionalFields.emailsUi as IDataObject).emailsValues as IDataObject[];
|
||||
body.emailAddresses = emailsValues;
|
||||
}
|
||||
|
||||
if (additionalFields.biographies) {
|
||||
body.biographies = [
|
||||
{
|
||||
value: additionalFields.biographies,
|
||||
contentType: 'TEXT_PLAIN',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFieldsValues = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
body.userDefined = customFieldsValues;
|
||||
}
|
||||
|
||||
if (additionalFields.group) {
|
||||
const memberships = (additionalFields.group as string[]).map((groupId: string) => {
|
||||
return {
|
||||
contactGroupMembership: {
|
||||
contactGroupResourceName: groupId,
|
||||
if (additionalFields.biographies) {
|
||||
body.biographies = [
|
||||
{
|
||||
value: additionalFields.biographies,
|
||||
contentType: 'TEXT_PLAIN',
|
||||
},
|
||||
};
|
||||
});
|
||||
];
|
||||
}
|
||||
|
||||
body.memberships = memberships;
|
||||
}
|
||||
if (additionalFields.customFieldsUi) {
|
||||
const customFieldsValues = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
body.userDefined = customFieldsValues;
|
||||
}
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/people:createContact`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
if (additionalFields.group) {
|
||||
const memberships = (additionalFields.group as string[]).map((groupId: string) => {
|
||||
return {
|
||||
contactGroupMembership: {
|
||||
contactGroupResourceName: groupId,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||
body.memberships = memberships;
|
||||
}
|
||||
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people/deleteContact
|
||||
if (operation === 'delete') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/people/${contactId}:deleteContact`,
|
||||
{},
|
||||
);
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people/get
|
||||
if (operation === 'get') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
const fields = this.getNodeParameter('fields', i) as string[];
|
||||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
|
||||
if (fields.includes('*')) {
|
||||
qs.personFields = allFields.join(',');
|
||||
} else {
|
||||
qs.personFields = (fields as string[]).join(',');
|
||||
}
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/people/${contactId}`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
|
||||
if (!rawData) {
|
||||
responseData = cleanData(responseData)[0];
|
||||
}
|
||||
|
||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people.connections/list
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const fields = this.getNodeParameter('fields', i) as string[];
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
|
||||
if (options.sortOrder) {
|
||||
qs.sortOrder = options.sortOrder as number;
|
||||
}
|
||||
|
||||
if (fields.includes('*')) {
|
||||
qs.personFields = allFields.join(',');
|
||||
} else {
|
||||
qs.personFields = (fields as string[]).join(',');
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'connections',
|
||||
'GET',
|
||||
`/people/me/connections`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.pageSize = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/people/me/connections`,
|
||||
{},
|
||||
'POST',
|
||||
`/people:createContact`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.connections;
|
||||
|
||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||
|
||||
}
|
||||
|
||||
if (!rawData) {
|
||||
responseData = cleanData(responseData);
|
||||
//https://developers.google.com/people/api/rest/v1/people/deleteContact
|
||||
if (operation === 'delete') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/people/${contactId}:deleteContact`,
|
||||
{},
|
||||
);
|
||||
responseData = { success: true };
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people/get
|
||||
if (operation === 'get') {
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
const fields = this.getNodeParameter('fields', i) as string[];
|
||||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
|
||||
for (let i = 0; i < responseData.length; i++) {
|
||||
responseData[i].contactId = responseData[i].resourceName.split('/')[1];
|
||||
}
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people/updateContact
|
||||
if (operation === 'update') {
|
||||
const updatePersonFields = [];
|
||||
if (fields.includes('*')) {
|
||||
qs.personFields = allFields.join(',');
|
||||
} else {
|
||||
qs.personFields = (fields as string[]).join(',');
|
||||
}
|
||||
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
|
||||
const fields = this.getNodeParameter('fields', i) as string[];
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
let etag;
|
||||
|
||||
if (updateFields.etag) {
|
||||
|
||||
etag = updateFields.etag as string;
|
||||
|
||||
} else {
|
||||
|
||||
const data = await googleApiRequest.call(
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/people/${contactId}`,
|
||||
{},
|
||||
{ personFields: 'Names' },
|
||||
qs,
|
||||
);
|
||||
|
||||
etag = data.etag;
|
||||
|
||||
}
|
||||
|
||||
if (fields.includes('*')) {
|
||||
qs.personFields = allFields.join(',');
|
||||
} else {
|
||||
qs.personFields = (fields as string[]).join(',');
|
||||
}
|
||||
|
||||
const body: IDataObject = {
|
||||
etag,
|
||||
names: [
|
||||
{},
|
||||
],
|
||||
};
|
||||
|
||||
if (updateFields.givenName) {
|
||||
//@ts-ignore
|
||||
body.names[0].givenName = updateFields.givenName as string;
|
||||
}
|
||||
|
||||
if (updateFields.familyName) {
|
||||
//@ts-ignore
|
||||
body.names[0].familyName = updateFields.familyName as string;
|
||||
}
|
||||
|
||||
if (updateFields.middleName) {
|
||||
//@ts-ignore
|
||||
body.names[0].middleName = updateFields.middleName as string;
|
||||
}
|
||||
|
||||
if (updateFields.honorificPrefix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificPrefix = updateFields.honorificPrefix as string;
|
||||
}
|
||||
|
||||
if (updateFields.honorificSuffix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificSuffix = updateFields.honorificSuffix as string;
|
||||
}
|
||||
|
||||
if (updateFields.companyUi) {
|
||||
const companyValues = (updateFields.companyUi as IDataObject).companyValues as IDataObject[];
|
||||
body.organizations = companyValues;
|
||||
updatePersonFields.push('organizations');
|
||||
}
|
||||
|
||||
if (updateFields.phoneUi) {
|
||||
const phoneValues = (updateFields.phoneUi as IDataObject).phoneValues as IDataObject[];
|
||||
body.phoneNumbers = phoneValues;
|
||||
updatePersonFields.push('phoneNumbers');
|
||||
}
|
||||
|
||||
if (updateFields.addressesUi) {
|
||||
const addressesValues = (updateFields.addressesUi as IDataObject).addressesValues as IDataObject[];
|
||||
body.addresses = addressesValues;
|
||||
updatePersonFields.push('addresses');
|
||||
}
|
||||
|
||||
if (updateFields.relationsUi) {
|
||||
const relationsValues = (updateFields.relationsUi as IDataObject).relationsValues as IDataObject[];
|
||||
body.relations = relationsValues;
|
||||
updatePersonFields.push('relations');
|
||||
}
|
||||
|
||||
if (updateFields.eventsUi) {
|
||||
const eventsValues = (updateFields.eventsUi as IDataObject).eventsValues as IDataObject[];
|
||||
for (let i = 0; i < eventsValues.length; i++) {
|
||||
const [month, day, year] = moment(eventsValues[i].date as string).format('MM/DD/YYYY').split('/');
|
||||
eventsValues[i] = {
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
},
|
||||
type: eventsValues[i].type,
|
||||
};
|
||||
if (!rawData) {
|
||||
responseData = cleanData(responseData)[0];
|
||||
}
|
||||
body.events = eventsValues;
|
||||
updatePersonFields.push('events');
|
||||
|
||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people.connections/list
|
||||
if (operation === 'getAll') {
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
const fields = this.getNodeParameter('fields', i) as string[];
|
||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
||||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||
|
||||
if (updateFields.birthday) {
|
||||
const [month, day, year] = moment(updateFields.birthday as string).format('MM/DD/YYYY').split('/');
|
||||
if (options.sortOrder) {
|
||||
qs.sortOrder = options.sortOrder as number;
|
||||
}
|
||||
|
||||
body.birthdays = [
|
||||
{
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
if (fields.includes('*')) {
|
||||
qs.personFields = allFields.join(',');
|
||||
} else {
|
||||
qs.personFields = (fields as string[]).join(',');
|
||||
}
|
||||
|
||||
if (returnAll) {
|
||||
responseData = await googleApiRequestAllItems.call(
|
||||
this,
|
||||
'connections',
|
||||
'GET',
|
||||
`/people/me/connections`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
} else {
|
||||
qs.pageSize = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/people/me/connections`,
|
||||
{},
|
||||
qs,
|
||||
);
|
||||
responseData = responseData.connections;
|
||||
}
|
||||
|
||||
if (!rawData) {
|
||||
responseData = cleanData(responseData);
|
||||
}
|
||||
|
||||
for (let i = 0; i < responseData.length; i++) {
|
||||
responseData[i].contactId = responseData[i].resourceName.split('/')[1];
|
||||
}
|
||||
}
|
||||
//https://developers.google.com/people/api/rest/v1/people/updateContact
|
||||
if (operation === 'update') {
|
||||
const updatePersonFields = [];
|
||||
|
||||
const contactId = this.getNodeParameter('contactId', i) as string;
|
||||
|
||||
const fields = this.getNodeParameter('fields', i) as string[];
|
||||
|
||||
const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
|
||||
|
||||
let etag;
|
||||
|
||||
if (updateFields.etag) {
|
||||
|
||||
etag = updateFields.etag as string;
|
||||
|
||||
} else {
|
||||
|
||||
const data = await googleApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/people/${contactId}`,
|
||||
{},
|
||||
{ personFields: 'Names' },
|
||||
);
|
||||
|
||||
etag = data.etag;
|
||||
|
||||
}
|
||||
|
||||
if (fields.includes('*')) {
|
||||
qs.personFields = allFields.join(',');
|
||||
} else {
|
||||
qs.personFields = (fields as string[]).join(',');
|
||||
}
|
||||
|
||||
const body: IDataObject = {
|
||||
etag,
|
||||
names: [
|
||||
{},
|
||||
],
|
||||
};
|
||||
|
||||
if (updateFields.givenName) {
|
||||
//@ts-ignore
|
||||
body.names[0].givenName = updateFields.givenName as string;
|
||||
}
|
||||
|
||||
if (updateFields.familyName) {
|
||||
//@ts-ignore
|
||||
body.names[0].familyName = updateFields.familyName as string;
|
||||
}
|
||||
|
||||
if (updateFields.middleName) {
|
||||
//@ts-ignore
|
||||
body.names[0].middleName = updateFields.middleName as string;
|
||||
}
|
||||
|
||||
if (updateFields.honorificPrefix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificPrefix = updateFields.honorificPrefix as string;
|
||||
}
|
||||
|
||||
if (updateFields.honorificSuffix) {
|
||||
//@ts-ignore
|
||||
body.names[0].honorificSuffix = updateFields.honorificSuffix as string;
|
||||
}
|
||||
|
||||
if (updateFields.companyUi) {
|
||||
const companyValues = (updateFields.companyUi as IDataObject).companyValues as IDataObject[];
|
||||
body.organizations = companyValues;
|
||||
updatePersonFields.push('organizations');
|
||||
}
|
||||
|
||||
if (updateFields.phoneUi) {
|
||||
const phoneValues = (updateFields.phoneUi as IDataObject).phoneValues as IDataObject[];
|
||||
body.phoneNumbers = phoneValues;
|
||||
updatePersonFields.push('phoneNumbers');
|
||||
}
|
||||
|
||||
if (updateFields.addressesUi) {
|
||||
const addressesValues = (updateFields.addressesUi as IDataObject).addressesValues as IDataObject[];
|
||||
body.addresses = addressesValues;
|
||||
updatePersonFields.push('addresses');
|
||||
}
|
||||
|
||||
if (updateFields.relationsUi) {
|
||||
const relationsValues = (updateFields.relationsUi as IDataObject).relationsValues as IDataObject[];
|
||||
body.relations = relationsValues;
|
||||
updatePersonFields.push('relations');
|
||||
}
|
||||
|
||||
if (updateFields.eventsUi) {
|
||||
const eventsValues = (updateFields.eventsUi as IDataObject).eventsValues as IDataObject[];
|
||||
for (let i = 0; i < eventsValues.length; i++) {
|
||||
const [month, day, year] = moment(eventsValues[i].date as string).format('MM/DD/YYYY').split('/');
|
||||
eventsValues[i] = {
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
},
|
||||
type: eventsValues[i].type,
|
||||
};
|
||||
}
|
||||
body.events = eventsValues;
|
||||
updatePersonFields.push('events');
|
||||
}
|
||||
|
||||
if (updateFields.birthday) {
|
||||
const [month, day, year] = moment(updateFields.birthday as string).format('MM/DD/YYYY').split('/');
|
||||
|
||||
body.birthdays = [
|
||||
{
|
||||
date: {
|
||||
day,
|
||||
month,
|
||||
year,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
];
|
||||
|
||||
updatePersonFields.push('birthdays');
|
||||
}
|
||||
updatePersonFields.push('birthdays');
|
||||
}
|
||||
|
||||
if (updateFields.emailsUi) {
|
||||
const emailsValues = (updateFields.emailsUi as IDataObject).emailsValues as IDataObject[];
|
||||
body.emailAddresses = emailsValues;
|
||||
updatePersonFields.push('emailAddresses');
|
||||
}
|
||||
if (updateFields.emailsUi) {
|
||||
const emailsValues = (updateFields.emailsUi as IDataObject).emailsValues as IDataObject[];
|
||||
body.emailAddresses = emailsValues;
|
||||
updatePersonFields.push('emailAddresses');
|
||||
}
|
||||
|
||||
if (updateFields.biographies) {
|
||||
body.biographies = [
|
||||
{
|
||||
value: updateFields.biographies,
|
||||
contentType: 'TEXT_PLAIN',
|
||||
},
|
||||
];
|
||||
updatePersonFields.push('biographies');
|
||||
}
|
||||
|
||||
if (updateFields.customFieldsUi) {
|
||||
const customFieldsValues = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
body.userDefined = customFieldsValues;
|
||||
updatePersonFields.push('userDefined');
|
||||
}
|
||||
|
||||
if (updateFields.group) {
|
||||
const memberships = (updateFields.group as string[]).map((groupId: string) => {
|
||||
return {
|
||||
contactGroupMembership: {
|
||||
contactGroupResourceName: groupId,
|
||||
if (updateFields.biographies) {
|
||||
body.biographies = [
|
||||
{
|
||||
value: updateFields.biographies,
|
||||
contentType: 'TEXT_PLAIN',
|
||||
},
|
||||
};
|
||||
});
|
||||
];
|
||||
updatePersonFields.push('biographies');
|
||||
}
|
||||
|
||||
body.memberships = memberships;
|
||||
updatePersonFields.push('memberships');
|
||||
if (updateFields.customFieldsUi) {
|
||||
const customFieldsValues = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[];
|
||||
body.userDefined = customFieldsValues;
|
||||
updatePersonFields.push('userDefined');
|
||||
}
|
||||
|
||||
if (updateFields.group) {
|
||||
const memberships = (updateFields.group as string[]).map((groupId: string) => {
|
||||
return {
|
||||
contactGroupMembership: {
|
||||
contactGroupResourceName: groupId,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
body.memberships = memberships;
|
||||
updatePersonFields.push('memberships');
|
||||
}
|
||||
|
||||
if ((body.names as IDataObject[]).length > 0) {
|
||||
updatePersonFields.push('names');
|
||||
}
|
||||
|
||||
qs.updatePersonFields = updatePersonFields.join(',');
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/people/${contactId}:updateContact`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
|
||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||
}
|
||||
|
||||
if ((body.names as IDataObject[]).length > 0) {
|
||||
updatePersonFields.push('names');
|
||||
}
|
||||
|
||||
qs.updatePersonFields = updatePersonFields.join(',');
|
||||
|
||||
responseData = await googleApiRequest.call(
|
||||
this,
|
||||
'PATCH',
|
||||
`/people/${contactId}:updateContact`,
|
||||
body,
|
||||
qs,
|
||||
);
|
||||
|
||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else if (responseData !== undefined) {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
} catch (error) {
|
||||
if (this.continueOnFail()) {
|
||||
returnData.push({ error: error.message });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (Array.isArray(responseData)) {
|
||||
returnData.push.apply(returnData, responseData as IDataObject[]);
|
||||
} else if (responseData !== undefined) {
|
||||
returnData.push(responseData as IDataObject);
|
||||
}
|
||||
return [this.helpers.returnJsonArray(returnData)];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user