mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
✨ Add query support to people:getAll - Google Contacts (#2552)
* Add query support to people:getAll
* ⚡ Fix typo
This commit is contained in:
parent
4adb9b83c5
commit
556e8e9417
|
@ -887,6 +887,43 @@ export const contactFields: INodeProperties[] = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'A field mask to restrict which fields on each person are returned. Multiple fields can be specified by separating them with commas.',
|
description: 'A field mask to restrict which fields on each person are returned. Multiple fields can be specified by separating them with commas.',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Use Query',
|
||||||
|
name: 'useQuery',
|
||||||
|
type: 'boolean',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'contact',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: false,
|
||||||
|
description: `Whether or not to use a query to filter the results`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Query',
|
||||||
|
name: 'query',
|
||||||
|
type: 'string',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'getAll',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'contact',
|
||||||
|
],
|
||||||
|
useQuery: [
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
default: '',
|
||||||
|
description: `The plain-text query for the request. The query is used to match prefix phrases of the fields on a person. For example, a person with name "foo name" matches queries such as "f", "fo", "foo", "foo n", "nam", etc., but not "oo n".`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'RAW Data',
|
displayName: 'RAW Data',
|
||||||
name: 'rawData',
|
name: 'rawData',
|
||||||
|
@ -918,6 +955,9 @@ export const contactFields: INodeProperties[] = [
|
||||||
resource: [
|
resource: [
|
||||||
'contact',
|
'contact',
|
||||||
],
|
],
|
||||||
|
useQuery: [
|
||||||
|
false,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
|
|
|
@ -24,6 +24,7 @@ import {
|
||||||
} from './ContactDescription';
|
} from './ContactDescription';
|
||||||
|
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
import { IData } from '../Analytics/Interfaces';
|
||||||
|
|
||||||
export class GoogleContacts implements INodeType {
|
export class GoogleContacts implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -264,11 +265,19 @@ export class GoogleContacts implements INodeType {
|
||||||
responseData.contactId = responseData.resourceName.split('/')[1];
|
responseData.contactId = responseData.resourceName.split('/')[1];
|
||||||
}
|
}
|
||||||
//https://developers.google.com/people/api/rest/v1/people.connections/list
|
//https://developers.google.com/people/api/rest/v1/people.connections/list
|
||||||
|
//https://developers.google.com/people/api/rest/v1/people/searchContacts
|
||||||
if (operation === 'getAll') {
|
if (operation === 'getAll') {
|
||||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||||
const fields = this.getNodeParameter('fields', i) as string[];
|
const fields = this.getNodeParameter('fields', i) as string[];
|
||||||
const options = this.getNodeParameter('options', i) as IDataObject;
|
const options = this.getNodeParameter('options', i, {}) as IDataObject;
|
||||||
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
const rawData = this.getNodeParameter('rawData', i) as boolean;
|
||||||
|
const useQuery = this.getNodeParameter('useQuery', i) as boolean;
|
||||||
|
|
||||||
|
const endpoint = (useQuery) ? ':searchContacts' : '/me/connections';
|
||||||
|
|
||||||
|
if (useQuery) {
|
||||||
|
qs.query = this.getNodeParameter('query', i) as string;
|
||||||
|
}
|
||||||
|
|
||||||
if (options.sortOrder) {
|
if (options.sortOrder) {
|
||||||
qs.sortOrder = options.sortOrder as number;
|
qs.sortOrder = options.sortOrder as number;
|
||||||
|
@ -280,25 +289,35 @@ export class GoogleContacts implements INodeType {
|
||||||
qs.personFields = (fields as string[]).join(',');
|
qs.personFields = (fields as string[]).join(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (useQuery) {
|
||||||
|
qs.readMask = qs.personFields;
|
||||||
|
delete qs.personFields;
|
||||||
|
}
|
||||||
|
|
||||||
if (returnAll) {
|
if (returnAll) {
|
||||||
responseData = await googleApiRequestAllItems.call(
|
responseData = await googleApiRequestAllItems.call(
|
||||||
this,
|
this,
|
||||||
'connections',
|
(useQuery) ? 'results' : 'connections',
|
||||||
'GET',
|
'GET',
|
||||||
`/people/me/connections`,
|
`/people${endpoint}`,
|
||||||
{},
|
{},
|
||||||
qs,
|
qs,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (useQuery) {
|
||||||
|
responseData = responseData.map((result: IDataObject) => result.person);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
qs.pageSize = this.getNodeParameter('limit', i) as number;
|
qs.pageSize = this.getNodeParameter('limit', i) as number;
|
||||||
responseData = await googleApiRequest.call(
|
responseData = await googleApiRequest.call(
|
||||||
this,
|
this,
|
||||||
'GET',
|
'GET',
|
||||||
`/people/me/connections`,
|
`/people${endpoint}`,
|
||||||
{},
|
{},
|
||||||
qs,
|
qs,
|
||||||
);
|
);
|
||||||
responseData = responseData.connections;
|
responseData = responseData.connections || responseData.results.map((result: IDataObject) => result.person);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rawData) {
|
if (!rawData) {
|
||||||
|
|
Loading…
Reference in a new issue