From 8e190d24a573a4ee8bad5277e560893bb1322836 Mon Sep 17 00:00:00 2001 From: Jan Oberhauser Date: Sat, 11 Apr 2020 14:56:25 +0200 Subject: [PATCH] :zap: Small improvement to Zendesk-Node --- .../nodes/Zendesk/TicketDescription.ts | 217 ++++++------------ .../nodes-base/nodes/Zendesk/Zendesk.node.ts | 41 +--- 2 files changed, 78 insertions(+), 180 deletions(-) diff --git a/packages/nodes-base/nodes/Zendesk/TicketDescription.ts b/packages/nodes-base/nodes/Zendesk/TicketDescription.ts index f5daab65358..3bb3d41417c 100644 --- a/packages/nodes-base/nodes/Zendesk/TicketDescription.ts +++ b/packages/nodes-base/nodes/Zendesk/TicketDescription.ts @@ -109,6 +109,41 @@ export const ticketFields = [ }, }, options: [ + { + displayName: 'Custom Fields', + name: 'customFieldsUi', + placeholder: 'Add Custom Field', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + displayName: 'Custom Field', + name: 'customFieldsValues', + values: [ + { + displayName: 'ID', + name: 'id', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getCustomFields', + }, + default: '', + description: 'Custom field ID', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + description: 'Custom field Value.', + }, + ], + }, + ], + }, { displayName: 'External ID', name: 'externalId', @@ -206,54 +241,6 @@ export const ticketFields = [ }, ], }, - { - displayName: 'Custom Fields', - name: 'customFieldsUi', - placeholder: 'Add Custom Field', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - displayOptions: { - show: { - resource: [ - 'ticket', - ], - operation: [ - 'create', - ], - jsonParameters: [ - false, - ], - }, - }, - default: {}, - options: [ - { - displayName: 'Custom Field', - name: 'customFieldsValues', - values: [ - { - displayName: 'ID', - name: 'id', - type: 'options', - typeOptions: { - loadOptionsMethod: 'getCustomFields', - }, - default: '', - description: 'Custom field ID', - }, - { - displayName: 'Value', - name: 'value', - type: 'string', - default: '', - description: 'Custom field Value.', - }, - ], - }, - ], - }, { displayName: ' Additional Fields', name: 'additionalFieldsJson', @@ -275,30 +262,9 @@ export const ticketFields = [ ], }, }, + description: `Object of values to set as described here.`, }, - { - displayName: ' Custom Fields', - name: 'customFieldsJson', - type: 'json', - typeOptions: { - alwaysOpenEditWindow: true, - }, - default: '', - displayOptions: { - show: { - resource: [ - 'ticket', - ], - operation: [ - 'create', - ], - jsonParameters: [ - true, - ], - }, - }, - description: `Array of customs fields Details`, - }, + /* -------------------------------------------------------------------------- */ /* ticket:update */ /* -------------------------------------------------------------------------- */ @@ -357,6 +323,41 @@ export const ticketFields = [ }, }, options: [ + { + displayName: 'Custom Fields', + name: 'customFieldsUi', + placeholder: 'Add Custom Field', + type: 'fixedCollection', + typeOptions: { + multipleValues: true, + }, + default: {}, + options: [ + { + displayName: 'Custom Field', + name: 'customFieldsValues', + values: [ + { + displayName: 'ID', + name: 'id', + type: 'options', + typeOptions: { + loadOptionsMethod: 'getCustomFields', + }, + default: '', + description: 'Custom field ID', + }, + { + displayName: 'Value', + name: 'value', + type: 'string', + default: '', + description: 'Custom field Value.', + }, + ], + }, + ], + }, { displayName: 'External ID', name: 'externalId', @@ -454,54 +455,6 @@ export const ticketFields = [ }, ], }, - { - displayName: 'Custom Fields', - name: 'customFieldsUi', - placeholder: 'Add Custom Field', - type: 'fixedCollection', - typeOptions: { - multipleValues: true, - }, - displayOptions: { - show: { - resource: [ - 'ticket', - ], - operation: [ - 'update', - ], - jsonParameters: [ - false, - ], - }, - }, - default: {}, - options: [ - { - displayName: 'Custom Field', - name: 'customFieldsValues', - values: [ - { - displayName: 'ID', - name: 'id', - type: 'options', - typeOptions: { - loadOptionsMethod: 'getCustomFields', - }, - default: '', - description: 'Custom field ID', - }, - { - displayName: 'Value', - name: 'value', - type: 'string', - default: '', - description: 'Custom field Value.', - }, - ], - }, - ], - }, { displayName: ' Update Fields', name: 'updateFieldsJson', @@ -523,31 +476,9 @@ export const ticketFields = [ ], }, }, + description: `Object of values to update as described here.`, }, - { - displayName: ' Custom Fields', - name: 'customFieldsJson', - type: 'json', - typeOptions: { - alwaysOpenEditWindow: true, - }, - default: '', - displayOptions: { - show: { - resource: [ - 'ticket', - ], - operation: [ - 'update', - ], - jsonParameters: [ - true, - ], - }, - }, - required: true, - description: `Array of customs fields Details`, - }, + /* -------------------------------------------------------------------------- */ /* ticket:get */ /* -------------------------------------------------------------------------- */ diff --git a/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts b/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts index a64feb9ca5a..8a2586d8d8c 100644 --- a/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts +++ b/packages/nodes-base/nodes/Zendesk/Zendesk.node.ts @@ -167,20 +167,6 @@ export class Zendesk implements INodeType { comment, }; if (jsonParameters) { - - const customFieldsJson = this.getNodeParameter('customFieldsJson', i) as string; - - if (customFieldsJson !== '' ) { - - if (validateJSON(customFieldsJson) !== undefined) { - - body.custom_fields = JSON.parse(customFieldsJson); - - } else { - throw new Error('Custom fields must be a valid JSON'); - } - } - const additionalFieldsJson = this.getNodeParameter('additionalFieldsJson', i) as string; if (additionalFieldsJson !== '' ) { @@ -194,13 +180,10 @@ export class Zendesk implements INodeType { } } - } else { const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; - const customFields = (this.getNodeParameter('customFieldsUi', i) as IDataObject).customFieldsValues as IDataObject[]; - if (additionalFields.type) { body.type = additionalFields.type as string; } @@ -222,8 +205,8 @@ export class Zendesk implements INodeType { if (additionalFields.tags) { body.tags = additionalFields.tags as string[]; } - if (customFields) { - body.custom_fields = customFields; + if (additionalFields.customFieldsUi) { + body.custom_fields = (additionalFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; } } responseData = await zendeskApiRequest.call(this, 'POST', '/tickets', { ticket: body }); @@ -236,20 +219,6 @@ export class Zendesk implements INodeType { const body: ITicket = {}; if (jsonParameters) { - - const customFieldsJson = this.getNodeParameter('customFieldsJson', i) as string; - - if (customFieldsJson !== '' ) { - - if (validateJSON(customFieldsJson) !== undefined) { - - body.custom_fields = JSON.parse(customFieldsJson); - - } else { - throw new Error('Custom fields must be a valid JSON'); - } - } - const updateFieldsJson = this.getNodeParameter('updateFieldsJson', i) as string; if (updateFieldsJson !== '' ) { @@ -267,8 +236,6 @@ export class Zendesk implements INodeType { const updateFields = this.getNodeParameter('updateFields', i) as IDataObject; - const customFields = (this.getNodeParameter('customFieldsUi', i) as IDataObject).customFieldsValues as IDataObject[]; - if (updateFields.type) { body.type = updateFields.type as string; } @@ -290,8 +257,8 @@ export class Zendesk implements INodeType { if (updateFields.tags) { body.tags = updateFields.tags as string[]; } - if (customFields) { - body.custom_fields = customFields; + if (updateFields.customFieldsUi) { + body.custom_fields = (updateFields.customFieldsUi as IDataObject).customFieldsValues as IDataObject[]; } } responseData = await zendeskApiRequest.call(this, 'PUT', `/tickets/${ticketId}`, { ticket: body });