Minor improvements to Google Contacts-Node

This commit is contained in:
Jan Oberhauser
2020-08-15 23:26:01 +02:00
parent eb9644f7de
commit b965dc0155
3 changed files with 39 additions and 40 deletions

View File

@@ -1,7 +1,6 @@
import { import {
INodeProperties, INodeProperties,
} from 'n8n-workflow'; } from 'n8n-workflow';
import { LoadNodeParameterOptions } from 'n8n-core';
export const contactOperations = [ export const contactOperations = [
{ {
@@ -471,57 +470,57 @@ export const contactFields = [
type: 'options', type: 'options',
options: [ options: [
{ {
name: 'Spouse', name: 'Assistant',
value: 'spouse', value: 'assistant',
},
{
name: 'Child',
value: 'child',
},
{
name: 'Mother',
value: 'mother',
},
{
name: 'Father',
value: 'father',
},
{
name: 'Parent',
value: 'parent',
}, },
{ {
name: 'Brother', name: 'Brother',
value: 'brother', value: 'brother',
}, },
{ {
name: 'Sister', name: 'Child',
value: 'sister', value: 'child',
},
{
name: 'Friend',
value: 'friend',
},
{
name: 'Relative',
value: 'relative',
}, },
{ {
name: 'Domestic Partner', name: 'Domestic Partner',
value: 'domesticPartner', value: 'domesticPartner',
}, },
{
name: 'Father',
value: 'father',
},
{
name: 'Friend',
value: 'friend',
},
{ {
name: 'Manager', name: 'Manager',
value: 'manager', value: 'manager',
}, },
{ {
name: 'Assistant', name: 'Mother',
value: 'assistant', value: 'mother',
},
{
name: 'Parent',
value: 'parent',
}, },
{ {
name: 'Referred By', name: 'Referred By',
value: 'referredBy', value: 'referredBy',
}, },
{
name: 'Relative',
value: 'relative',
},
{
name: 'Sister',
value: 'sister',
},
{
name: 'Spouse',
value: 'spouse',
},
], ],
default: '', default: '',
description: `The person's relation to the other person. The type can be custom or one of these predefined values`, description: `The person's relation to the other person. The type can be custom or one of these predefined values`,

View File

@@ -1,6 +1,6 @@
import { import {
OptionsWithUri, OptionsWithUri,
} from 'request'; } from 'request';
import { import {
IExecuteFunctions, IExecuteFunctions,
@@ -57,7 +57,7 @@ export async function googleApiRequest(this: IExecuteFunctions | IExecuteSingleF
} }
} }
export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string ,method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOptionsFunctions, propertyName: string, method: string, endpoint: string, body: any = {}, query: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const returnData: IDataObject[] = []; const returnData: IDataObject[] = [];
@@ -76,7 +76,7 @@ export async function googleApiRequestAllItems(this: IExecuteFunctions | ILoadOp
return returnData; return returnData;
} }
export const allFields = [ export const allFields = [
'addresses', 'addresses',
'biographies', 'biographies',
'birthdays', 'birthdays',
@@ -103,14 +103,14 @@ export const allFields = [
'userDefined', 'userDefined',
]; ];
export function cleanData(responseData: any) { export function cleanData(responseData: any) { // tslint:disable-line:no-any
const fields = ['emailAddresses', 'phoneNumbers', 'relations', 'events', 'addresses']; const fields = ['emailAddresses', 'phoneNumbers', 'relations', 'events', 'addresses'];
const newResponseData = []; const newResponseData = [];
if (!Array.isArray(responseData)) { if (!Array.isArray(responseData)) {
responseData = [responseData]; responseData = [responseData];
} }
for (let y = 0; y < responseData.length; y++ ) { for (let y = 0; y < responseData.length; y++) {
const object: { [key: string]: any } = {}; const object: { [key: string]: any } = {}; // tslint:disable-line:no-any
for (const key of Object.keys(responseData[y])) { for (const key of Object.keys(responseData[y])) {
if (key === 'metadata') { if (key === 'metadata') {
continue; continue;
@@ -140,7 +140,7 @@ export function cleanData(responseData: any) {
} }
} }
if (fields.includes(key)) { if (fields.includes(key)) {
const value: { [key: string]: any } = {}; const value: { [key: string]: any } = {}; // tslint:disable-line:no-any
for (const data of responseData[y][key]) { for (const data of responseData[y][key]) {
let result; let result;
if (value[data.type] === undefined) { if (value[data.type] === undefined) {

View File

@@ -78,7 +78,7 @@ export class GoogleContacts implements INodeType {
'contactGroups', 'contactGroups',
'GET', 'GET',
`/contactGroups`, `/contactGroups`,
); );
for (const group of groups) { for (const group of groups) {
const groupName = group.name; const groupName = group.name;
const groupId = group.resourceName; const groupId = group.resourceName;
@@ -294,7 +294,7 @@ export class GoogleContacts implements INodeType {
responseData = cleanData(responseData); responseData = cleanData(responseData);
} }
for (let i = 0; i < responseData.length; i++ ) { for (let i = 0; i < responseData.length; i++) {
responseData[i].contactId = responseData[i].resourceName.split('/')[1]; responseData[i].contactId = responseData[i].resourceName.split('/')[1];
} }
} }