* add sfdc user node interface

* add sfdc user node description for get method

* sfdc user node getall

* sfdc user node support limit

* sfdc user node support options

* sfdc user node update user operations

* sfdc add usr node query logic

*  Small improvements

Co-authored-by: YErii <yeriime@outlook.com>
This commit is contained in:
Ricardo Espinoza 2020-09-06 15:27:24 -04:00 committed by GitHub
parent c42ae57dc1
commit 5a0e356ab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 179 additions and 2 deletions

View file

@ -71,7 +71,13 @@ import {
import { import {
ITask, ITask,
} from './TaskInterface'; } from './TaskInterface';
import {
userFields,
userOperations,
} from './UserDescription';
import {
IUser,
} from './UserInterface';
export class Salesforce implements INodeType { export class Salesforce implements INodeType {
description: INodeTypeDescription = { description: INodeTypeDescription = {
@ -135,7 +141,11 @@ export class Salesforce implements INodeType {
value: 'task', value: 'task',
description: 'Represents a business activity such as making a phone call or other to-do items. In the user interface, and records are collectively referred to as activities.', description: 'Represents a business activity such as making a phone call or other to-do items. In the user interface, and records are collectively referred to as activities.',
}, },
{
name: 'User',
value: 'user',
description: 'Represents a person, which is one user in system.',
},
], ],
default: 'lead', default: 'lead',
description: 'Resource to consume.', description: 'Resource to consume.',
@ -154,6 +164,8 @@ export class Salesforce implements INodeType {
...taskFields, ...taskFields,
...attachmentOperations, ...attachmentOperations,
...attachmentFields, ...attachmentFields,
...userOperations,
...userFields,
], ],
}; };
@ -1885,6 +1897,35 @@ export class Salesforce implements INodeType {
responseData = await salesforceApiRequest.call(this, 'GET', '/sobjects/attachment'); responseData = await salesforceApiRequest.call(this, 'GET', '/sobjects/attachment');
} }
} }
if (resource === 'user') {
//https://developer.salesforce.com/docs/api-explorer/sobject/User/get-user-id
if (operation === 'get') {
const userId = this.getNodeParameter('userId', i) as string;
responseData = await salesforceApiRequest.call(this, 'GET', `/sobjects/user/${userId}`);
}
//https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_query.htm
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const options = this.getNodeParameter('options', i) as IDataObject;
const fields = ['id,name,email'];
if (options.fields) {
// @ts-ignore
fields.push(...options.fields.split(','));
}
try {
if (returnAll) {
qs.q = `SELECT ${fields.join(',')} FROM User`;
responseData = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs);
} else {
const limit = this.getNodeParameter('limit', i) as number;
qs.q = `SELECT ${fields.join(',')} FROM User Limit ${limit}`;
responseData = await salesforceApiRequestAllItems.call(this, 'records', 'GET', '/query', {}, qs);
}
} catch(err) {
throw new Error(`Salesforce Error: ${err}`);
}
}
}
if (Array.isArray(responseData)) { if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]); returnData.push.apply(returnData, responseData as IDataObject[]);
} else { } else {

View file

@ -0,0 +1,126 @@
import {
INodeProperties,
} from 'n8n-workflow';
export const userOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'user',
],
},
},
options: [
{
name: 'Get',
value: 'get',
description: 'Get a user',
},
{
name: 'Get All',
value: 'getAll',
description: 'Get all users',
},
],
default: 'get',
description: 'The operation to perform.'
}
] as INodeProperties[];
export const userFields = [
/* -------------------------------------------------------------------------- */
/* user:get */
/* -------------------------------------------------------------------------- */
{
displayName: 'User ID',
name: 'userId',
type: 'string',
required: true,
default: '',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'get',
],
},
},
description: 'Id of user that needs to be fetched'
},
/* -------------------------------------------------------------------------- */
/* user:getAll */
/* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
type: 'boolean',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getAll',
],
}
},
default: false,
description: 'If all results should be returned or only up to a given limit.'
},
{
displayName: 'Limit',
name: 'limit',
type: 'number',
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getAll',
],
returnAll: [
false,
],
},
},
typeOptions: {
minValue: 1,
maxValue: 100
},
default: 50,
description: 'How many results to return.'
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {
resource: [
'user',
],
operation: [
'getAll',
],
},
},
options: [
{
displayName: 'Fields',
name: 'fields',
type: 'string',
default: '',
description: 'Fields to include separated by ,'
},
],
},
] as INodeProperties[];

View file

@ -0,0 +1,10 @@
export interface IUser {
Alias?: string;
Department?: string;
Division?: string;
Email?: string;
IsActive?: boolean;
MobilePhone?: string;
Title?: string;
Username?: string;
}