mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-12 13:27:31 -08:00
Deal Get / Getall / Delete / update / create
This commit is contained in:
parent
b2b6656d8d
commit
08220195a2
|
@ -23,6 +23,7 @@ import {
|
|||
|
||||
import { agileCrmApiRequest, validateJSON, agileCrmApiRequestUpdate} from './GenericFunctions';
|
||||
import { IContact, IProperty, IContactUpdate } from './ContactInterface';
|
||||
import { IDeal } from './DealInterface';
|
||||
|
||||
|
||||
export class AgileCrm implements INodeType {
|
||||
|
@ -483,6 +484,99 @@ export class AgileCrm implements INodeType {
|
|||
responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {});
|
||||
}
|
||||
}
|
||||
|
||||
if(operation === 'create'){
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
const body: IDeal = {};
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
|
||||
} else {
|
||||
throw new Error('Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
||||
body.close_date = new Date(this.getNodeParameter('closeDate', i) as string).getTime();
|
||||
body.expected_value = this.getNodeParameter('expectedValue', i) as number;
|
||||
body.milestone = this.getNodeParameter('milestone', i) as string;
|
||||
body.probability = this.getNodeParameter('probability', i) as number;
|
||||
body.name = this.getNodeParameter('name', i) as string;
|
||||
|
||||
if(additionalFields.contactIds){
|
||||
body.contactIds = additionalFields.contactIds as string[];
|
||||
}
|
||||
|
||||
if(additionalFields.customData){
|
||||
// @ts-ignore
|
||||
body.customData = additionalFields.customData.customProperty as IDealCustomProperty[];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let endpoint = 'api/opportunity'
|
||||
responseData = await agileCrmApiRequest.call(this, 'POST', endpoint, body);
|
||||
}
|
||||
|
||||
if(operation === 'update'){
|
||||
const jsonParameters = this.getNodeParameter('jsonParameters', i) as boolean;
|
||||
|
||||
const body: IDeal = {};
|
||||
|
||||
if (jsonParameters) {
|
||||
const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string;
|
||||
|
||||
if (additionalFieldsJson !== '' ) {
|
||||
|
||||
if (validateJSON(additionalFieldsJson) !== undefined) {
|
||||
|
||||
Object.assign(body, JSON.parse(additionalFieldsJson));
|
||||
|
||||
} else {
|
||||
throw new Error('Additional fields must be a valid JSON');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
body.id = this.getNodeParameter('dealId', i) as number;
|
||||
|
||||
if(additionalFields.expectedValue){
|
||||
body.expected_value = additionalFields.expectedValue as number;
|
||||
}
|
||||
|
||||
if(additionalFields.name){
|
||||
body.name = additionalFields.name as string;
|
||||
}
|
||||
|
||||
if(additionalFields.probability){
|
||||
body.probability = additionalFields.probability as number;
|
||||
}
|
||||
|
||||
if(additionalFields.contactIds){
|
||||
body.contactIds = additionalFields.contactIds as string[];
|
||||
}
|
||||
|
||||
if(additionalFields.customData){
|
||||
// @ts-ignore
|
||||
body.customData = additionalFields.customData.customProperty as IDealCustomProperty[];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let endpoint = 'api/opportunity/partial-update'
|
||||
responseData = await agileCrmApiRequest.call(this, 'PUT', endpoint, body);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ export const dealFields = [
|
|||
{
|
||||
displayName: 'Close Date',
|
||||
name: 'closeDate',
|
||||
type: 'string',
|
||||
type: 'dateTime',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
|
@ -126,6 +126,9 @@ export const dealFields = [
|
|||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
|
@ -148,6 +151,9 @@ export const dealFields = [
|
|||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 1,
|
||||
|
@ -166,6 +172,9 @@ export const dealFields = [
|
|||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
|
@ -188,6 +197,9 @@ export const dealFields = [
|
|||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 50,
|
||||
|
@ -206,6 +218,9 @@ export const dealFields = [
|
|||
operation: [
|
||||
'create',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
|
@ -324,14 +339,34 @@ export const dealFields = [
|
|||
]
|
||||
},
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:delete */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'delete',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Unique identifier for a particular deal',
|
||||
},
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* deal:update */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
{
|
||||
displayName: 'Close Date',
|
||||
name: 'closeDate',
|
||||
displayName: 'Deal ID',
|
||||
name: 'dealId',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
|
@ -345,88 +380,9 @@ export const dealFields = [
|
|||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Closing date of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Expected Value',
|
||||
name: 'expectedValue',
|
||||
type: 'number',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 10000
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Milestone',
|
||||
name: 'milestone',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Milestone of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Probability',
|
||||
name: 'probability',
|
||||
type: 'number',
|
||||
required: true,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: 50,
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
},
|
||||
},
|
||||
default: '',
|
||||
description: 'Name of deal.',
|
||||
description: 'Unique identifier for a particular deal',
|
||||
},
|
||||
|
||||
{
|
||||
displayName: 'JSON Parameters',
|
||||
name: 'jsonParameters',
|
||||
|
@ -469,39 +425,11 @@ export const dealFields = [
|
|||
description: `Object of values to set as described <a href="https://github.com/agilecrm/rest-api#1-deals---companies-api" target="_blank">here</a>.`,
|
||||
},
|
||||
{
|
||||
displayName: 'Contact IDs',
|
||||
name: 'contactIds',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add Contact ID',
|
||||
},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'deal',
|
||||
],
|
||||
operation: [
|
||||
'update',
|
||||
],
|
||||
jsonParameters: [
|
||||
false,
|
||||
],
|
||||
},
|
||||
},
|
||||
default: [],
|
||||
placeholder: 'Id',
|
||||
description: 'Id numbers of contacts.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Data',
|
||||
name: 'customData',
|
||||
type: 'fixedCollection',
|
||||
required: false,
|
||||
description: 'Custom Data.',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
type: 'collection',
|
||||
placeholder: 'Add Field',
|
||||
default: {},
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
|
@ -517,30 +445,86 @@ export const dealFields = [
|
|||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Data Properties',
|
||||
name: 'customDataProperties',
|
||||
values: [
|
||||
displayName: 'Expected Value',
|
||||
name: 'expectedValue',
|
||||
type: 'number',
|
||||
required: false,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 10000
|
||||
},
|
||||
default: '',
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Probability',
|
||||
name: 'probability',
|
||||
type: 'number',
|
||||
required: false,
|
||||
typeOptions: {
|
||||
minValue: 0,
|
||||
maxValue: 100
|
||||
},
|
||||
default: 50,
|
||||
description: 'Expected Value of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: '',
|
||||
description: 'Name of deal.',
|
||||
},
|
||||
{
|
||||
displayName: 'Contact Ids',
|
||||
name: 'contactIds',
|
||||
type: 'string',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
multipleValueButtonText: 'Add ID',
|
||||
},
|
||||
default: [],
|
||||
placeholder: 'ID',
|
||||
description: 'Unique contact identifiers.',
|
||||
},
|
||||
{
|
||||
displayName: 'Custom Data',
|
||||
name: 'customData',
|
||||
type: 'fixedCollection',
|
||||
required: false,
|
||||
description: 'Custom Data',
|
||||
typeOptions: {
|
||||
multipleValues: true,
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: 'name',
|
||||
description: 'Name of property',
|
||||
displayName: 'Property',
|
||||
name: 'customProperty',
|
||||
values: [
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Property name.'
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
required: false,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Property value.',
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
displayName: 'Value',
|
||||
name: 'value',
|
||||
type: 'string',
|
||||
required: true,
|
||||
default: "",
|
||||
placeholder: '',
|
||||
description: 'Value of property',
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
|
||||
]
|
||||
},
|
||||
|
||||
|
|
19
packages/nodes-base/nodes/AgileCrm/DealInterface.ts
Normal file
19
packages/nodes-base/nodes/AgileCrm/DealInterface.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import {
|
||||
IDataObject,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
export interface IDealCustomProperty {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface IDeal {
|
||||
id?: number,
|
||||
expected_value?: number,
|
||||
probability?: number,
|
||||
name?: string,
|
||||
close_date?: number,
|
||||
milestone?: string,
|
||||
contactIds?: string[],
|
||||
customData?: IDealCustomProperty[]
|
||||
}
|
|
@ -35,6 +35,7 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction
|
|||
if(method !== "GET" && method !== "DELETE"){
|
||||
options.body = body;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
return await this.helpers.request!(options);
|
||||
|
|
Loading…
Reference in a new issue