From b6e2ae770619d311ceb2ce621f77501ac438b215 Mon Sep 17 00:00:00 2001 From: ricardo Date: Thu, 23 Apr 2020 23:38:19 -0500 Subject: [PATCH] :zap: Added get user by id --- .../nodes/PagerDuty/PagerDuty.node.ts | 20 ++++++++ .../nodes/PagerDuty/UserDescription.ts | 51 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 packages/nodes-base/nodes/PagerDuty/UserDescription.ts diff --git a/packages/nodes-base/nodes/PagerDuty/PagerDuty.node.ts b/packages/nodes-base/nodes/PagerDuty/PagerDuty.node.ts index 9d2b9409ce..d53e5921b8 100644 --- a/packages/nodes-base/nodes/PagerDuty/PagerDuty.node.ts +++ b/packages/nodes-base/nodes/PagerDuty/PagerDuty.node.ts @@ -32,6 +32,11 @@ import { logEntryOperations, } from './LogEntryDescription'; +import { + userFields, + userOperations, +} from './UserDescription'; + import { IIncident, } from './IncidentInterface'; @@ -81,6 +86,10 @@ export class PagerDuty implements INodeType { name: 'Log Entry', value: 'logEntry', }, + { + name: 'User', + value: 'user', + }, ], default: 'incident', description: 'Resource to consume.', @@ -94,6 +103,9 @@ export class PagerDuty implements INodeType { // LOG ENTRY ...logEntryOperations, ...logEntryFields, + // USER + ...userOperations, + ...userFields, ], }; @@ -350,6 +362,14 @@ export class PagerDuty implements INodeType { } } } + if (resource === 'user') { + //https://developer.pagerduty.com/api-reference/reference/REST/openapiv3.json/paths/~1users~1%7Bid%7D/get + if (operation === 'get') { + const userId = this.getNodeParameter('userId', i) as string; + responseData = await pagerDutyApiRequest.call(this, 'GET', `/users/${userId}`); + responseData = responseData.user; + } + } if (Array.isArray(responseData)) { returnData.push.apply(returnData, responseData as IDataObject[]); } else { diff --git a/packages/nodes-base/nodes/PagerDuty/UserDescription.ts b/packages/nodes-base/nodes/PagerDuty/UserDescription.ts new file mode 100644 index 0000000000..c5e93c7ca5 --- /dev/null +++ b/packages/nodes-base/nodes/PagerDuty/UserDescription.ts @@ -0,0 +1,51 @@ +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', + }, + ], + 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: 'Unique identifier for the user.', + }, +] as INodeProperties[];