n8n-3867-progressively-apply-prettier-to-all (#3873)

* 🔨 formatting nodes with prettier
This commit is contained in:
Michael Kret
2022-08-17 18:50:24 +03:00
committed by GitHub
parent f2d326c7f0
commit 91d7e16c81
1072 changed files with 42357 additions and 59109 deletions

View File

@@ -1,7 +1,4 @@
import {
IExecuteFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IExecuteFunctions, ILoadOptionsFunctions } from 'n8n-core';
import {
IBinaryData,
@@ -19,58 +16,31 @@ import {
serviceNowApiRequest,
serviceNowDownloadAttachment,
serviceNowRequestAllItems,
sortData
sortData,
} from './GenericFunctions';
import {
attachmentFields,
attachmentOperations,
} from './AttachmentDescription';
import { attachmentFields, attachmentOperations } from './AttachmentDescription';
import {
businessServiceFields,
businessServiceOperations,
} from './BusinessServiceDescription';
import { businessServiceFields, businessServiceOperations } from './BusinessServiceDescription';
import {
configurationItemsFields,
configurationItemsOperations,
} from './ConfigurationItemsDescription';
import {
departmentFields,
departmentOperations,
} from './DepartmentDescription';
import { departmentFields, departmentOperations } from './DepartmentDescription';
import {
dictionaryFields,
dictionaryOperations,
} from './DictionaryDescription';
import { dictionaryFields, dictionaryOperations } from './DictionaryDescription';
import {
incidentFields,
incidentOperations,
} from './IncidentDescription';
import { incidentFields, incidentOperations } from './IncidentDescription';
import {
tableRecordFields,
tableRecordOperations,
} from './TableRecordDescription';
import { tableRecordFields, tableRecordOperations } from './TableRecordDescription';
import {
userFields,
userOperations,
} from './UserDescription';
import { userFields, userOperations } from './UserDescription';
import {
userGroupFields,
userGroupOperations,
} from './UserGroupDescription';
import { userGroupFields, userGroupOperations } from './UserGroupDescription';
import {
userRoleFields,
userRoleOperations,
} from './UserRoleDescription';
import { userRoleFields, userRoleOperations } from './UserRoleDescription';
export class ServiceNow implements INodeType {
description: INodeTypeDescription = {
@@ -92,9 +62,7 @@ export class ServiceNow implements INodeType {
required: true,
displayOptions: {
show: {
authentication: [
'oAuth2',
],
authentication: ['oAuth2'],
},
},
},
@@ -103,9 +71,7 @@ export class ServiceNow implements INodeType {
required: true,
displayOptions: {
show: {
authentication: [
'basicAuth',
],
authentication: ['basicAuth'],
},
},
},
@@ -214,7 +180,13 @@ export class ServiceNow implements INodeType {
loadOptions: {
async getTables(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const response = await serviceNowApiRequest.call(this, 'GET', `/now/doc/table/schema`, {}, {});
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/doc/table/schema`,
{},
{},
);
for (const table of response.result) {
returnData.push({
name: table.label,
@@ -240,7 +212,13 @@ export class ServiceNow implements INodeType {
sysparm_query: `name=${tableName}`,
sysparm_fields: 'column_label,element',
};
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/sys_dictionary`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/sys_dictionary`,
{},
qs,
);
for (const column of response.result) {
if (column.element) {
returnData.push({
@@ -256,7 +234,13 @@ export class ServiceNow implements INodeType {
const qs = {
sysparm_fields: 'name,sys_id',
};
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/cmdb_ci_service`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/cmdb_ci_service`,
{},
qs,
);
for (const column of response.result) {
returnData.push({
@@ -278,14 +262,25 @@ export class ServiceNow implements INodeType {
const additionalFields = this.getNodeParameter('additionalFields') as IDataObject;
const group = additionalFields.assignment_group;
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user_grmember', {}, {
sysparm_query: `group=${group}^`,
});
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user_grmember',
{},
{
sysparm_query: `group=${group}^`,
},
);
for (const column of response) {
if (column.user) {
const responseData = await serviceNowApiRequest.call(this, 'GET', `/now/table/sys_user/${column.user.value}`, {}, {});
const responseData = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/sys_user/${column.user.value}`,
{},
{},
);
const user = responseData.result;
returnData.push({
@@ -295,8 +290,13 @@ export class ServiceNow implements INodeType {
}
}
} else {
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user',
{},
qs,
);
for (const column of response) {
if (column.user_name) {
@@ -314,7 +314,13 @@ export class ServiceNow implements INodeType {
const qs = {
sysparm_fields: 'sys_id,name',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user_group', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user_group',
{},
qs,
);
for (const column of response) {
if (column.name) {
@@ -331,7 +337,13 @@ export class ServiceNow implements INodeType {
const qs = {
sysparm_fields: 'sys_id,name',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user_role', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user_role',
{},
qs,
);
for (const column of response) {
if (column.name) {
@@ -348,7 +360,13 @@ export class ServiceNow implements INodeType {
const qs = {
sysparm_fields: 'sys_id,name,sys_class_name',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/cmdb_ci', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/cmdb_ci',
{},
qs,
);
for (const column of response) {
if (column.name) {
@@ -367,14 +385,19 @@ export class ServiceNow implements INodeType {
sysparm_fields: 'label,value',
sysparm_query: 'element=category^name=incident',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_choice', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_choice',
{},
qs,
);
for (const column of response) {
returnData.push({
name: column.label,
value: column.value,
});
}
return sortData(returnData);
},
@@ -393,7 +416,13 @@ export class ServiceNow implements INodeType {
sysparm_fields: 'label,value',
sysparm_query: `name=incident^element=subcategory^dependent_value=${category}`,
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_choice', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_choice',
{},
qs,
);
for (const column of response) {
returnData.push({
@@ -410,31 +439,43 @@ export class ServiceNow implements INodeType {
sysparm_fields: 'label,value',
sysparm_query: 'element=state^name=incident',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_choice', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_choice',
{},
qs,
);
for (const column of response) {
returnData.push({
name: column.label,
value: column.value,
});
}
return sortData(returnData);
},
async getIncidentResolutionCodes(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
async getIncidentResolutionCodes(
this: ILoadOptionsFunctions,
): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
const qs = {
sysparm_fields: 'label,value',
sysparm_query: 'element=close_code^name=incident',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_choice', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_choice',
{},
qs,
);
for (const column of response) {
returnData.push({
name: column.label,
value: column.value,
});
}
return sortData(returnData);
},
@@ -444,14 +485,19 @@ export class ServiceNow implements INodeType {
sysparm_fields: 'label,value',
sysparm_query: 'element=hold_reason^name=incident',
};
const response = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_choice', {}, qs);
const response = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_choice',
{},
qs,
);
for (const column of response) {
returnData.push({
name: column.label,
value: column.value,
});
}
return sortData(returnData);
},
@@ -472,7 +518,6 @@ export class ServiceNow implements INodeType {
// https://developer.servicenow.com/dev.do#!/reference/api/rome/rest/c_AttachmentAPI
if (resource === 'attachment') {
if (operation === 'get') {
const attachmentsSysId = this.getNodeParameter('attachmentId', i) as string;
const download = this.getNodeParameter('download', i) as boolean;
const endpoint = `/now/attachment/${attachmentsSysId}`;
@@ -498,7 +543,6 @@ export class ServiceNow implements INodeType {
},
};
}
} else if (operation === 'getAll') {
const download = this.getNodeParameter('download', i) as boolean;
const tableName = this.getNodeParameter('tableName', i) as string;
@@ -516,10 +560,22 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/attachment', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/attachment',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/attachment', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/attachment',
{},
qs,
);
}
if (download) {
@@ -542,9 +598,8 @@ export class ServiceNow implements INodeType {
responseData = responseDataWithAttachments;
} else {
responseData = (responseData as IDataObject[]).map( data => ({ json: data }));
responseData = (responseData as IDataObject[]).map((data) => ({ json: data }));
}
} else if (operation === 'upload') {
const tableName = this.getNodeParameter('tableName', i) as string;
const recordId = this.getNodeParameter('id', i) as string;
@@ -556,7 +611,11 @@ export class ServiceNow implements INodeType {
if (items[i].binary && items[i].binary![inputDataFieldName]) {
binaryData = items[i].binary![inputDataFieldName];
} else {
throw new NodeOperationError(this.getNode(), `No binary data property "${inputDataFieldName}" does not exists on item!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`No binary data property "${inputDataFieldName}" does not exists on item!`,
{ itemIndex: i },
);
}
const headers: IDataObject = {
@@ -566,23 +625,31 @@ export class ServiceNow implements INodeType {
const qs: IDataObject = {
table_name: tableName,
table_sys_id: recordId,
file_name: binaryData.fileName ? binaryData.fileName : `${inputDataFieldName}.${binaryData.fileExtension}`,
file_name: binaryData.fileName
? binaryData.fileName
: `${inputDataFieldName}.${binaryData.fileExtension}`,
...options,
};
const body = await this.helpers.getBinaryDataBuffer(i, inputDataFieldName) as Buffer;
const body = (await this.helpers.getBinaryDataBuffer(i, inputDataFieldName)) as Buffer;
const response = await serviceNowApiRequest.call(this, 'POST', '/now/attachment/file', body, qs, '', {headers});
const response = await serviceNowApiRequest.call(
this,
'POST',
'/now/attachment/file',
body,
qs,
'',
{ headers },
);
responseData = response.result;
} else if (operation === 'delete') {
const attachmentsSysId = this.getNodeParameter('attachmentId', i) as string;
await serviceNowApiRequest.call(this, 'DELETE', `/now/attachment/${attachmentsSysId}`);
responseData = {'success': true};
responseData = { success: true };
}
} else if (resource === 'businessService') {
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -593,17 +660,26 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/cmdb_ci_service', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/cmdb_ci_service',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/cmdb_ci_service', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/cmdb_ci_service',
{},
qs,
);
}
}
} else if (resource === 'configurationItems') {
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -614,17 +690,26 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/cmdb_ci', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/cmdb_ci',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/cmdb_ci', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/cmdb_ci',
{},
qs,
);
}
}
} else if (resource === 'department') {
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -635,17 +720,26 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/cmn_department', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/cmn_department',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/cmn_department', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/cmn_department',
{},
qs,
);
}
}
} else if (resource === 'dictionary') {
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -656,17 +750,26 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/sys_dictionary', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/sys_dictionary',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_dictionary', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_dictionary',
{},
qs,
);
}
}
} else if (resource === 'incident') {
if (operation === 'create') {
const shortDescription = this.getNodeParameter('short_description', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const body = {
@@ -674,17 +777,22 @@ export class ServiceNow implements INodeType {
...additionalFields,
};
const response = await serviceNowApiRequest.call(this, 'POST', `/now/table/incident`, body);
const response = await serviceNowApiRequest.call(
this,
'POST',
`/now/table/incident`,
body,
);
responseData = response.result;
} else if (operation === 'delete') {
const id = this.getNodeParameter('id', i) as string;
responseData = await serviceNowApiRequest.call(this, 'DELETE', `/now/table/incident/${id}`);
responseData = await serviceNowApiRequest.call(
this,
'DELETE',
`/now/table/incident/${id}`,
);
responseData = { success: true };
} else if (operation === 'get') {
const id = this.getNodeParameter('id', i) as string;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -692,11 +800,15 @@ export class ServiceNow implements INodeType {
qs.sysparm_fields = (qs.sysparm_fields as string[]).join(',');
}
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/incident/${id}`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/incident/${id}`,
{},
qs,
);
responseData = response.result;
} else if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -707,39 +819,57 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/incident`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/incident`,
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', `/now/table/incident`, {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
`/now/table/incident`,
{},
qs,
);
}
} else if (operation === 'update') {
const id = this.getNodeParameter('id', i) as string;
const body = this.getNodeParameter('updateFields', i) as IDataObject;
const response = await serviceNowApiRequest.call(this, 'PATCH', `/now/table/incident/${id}`, body);
const response = await serviceNowApiRequest.call(
this,
'PATCH',
`/now/table/incident/${id}`,
body,
);
responseData = response.result;
} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not known!`,
{ itemIndex: i },
);
}
} else if (resource === 'tableRecord') {
if (operation === 'create') {
const tableName = this.getNodeParameter('tableName', i) as string;
const dataToSend = this.getNodeParameter('dataToSend', i) as string;
let body = {};
if (dataToSend === 'mapInput') {
const inputsToIgnore = (this.getNodeParameter('inputsToIgnore', i) as string).split(',').map(field => field.trim());
const inputsToIgnore = (this.getNodeParameter('inputsToIgnore', i) as string)
.split(',')
.map((field) => field.trim());
body = Object.entries(items[i].json)
.filter(([key]) => !inputsToIgnore.includes(key))
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {});
} else if (dataToSend === 'columns') {
const fieldsToSend = this.getNodeParameter('fieldsToSend', i) as {
field: IDataObject[]
field: IDataObject[];
};
body = fieldsToSend.field.reduce((obj, field) => {
obj[field.column as string] = field.value;
@@ -747,18 +877,23 @@ export class ServiceNow implements INodeType {
}, {});
}
const response = await serviceNowApiRequest.call(this, 'POST', `/now/table/${tableName}`, body);
const response = await serviceNowApiRequest.call(
this,
'POST',
`/now/table/${tableName}`,
body,
);
responseData = response.result;
} else if (operation === 'delete') {
const tableName = this.getNodeParameter('tableName', i) as string;
const id = this.getNodeParameter('id', i) as string;
responseData = await serviceNowApiRequest.call(this, 'DELETE', `/now/table/${tableName}/${id}`);
responseData = await serviceNowApiRequest.call(
this,
'DELETE',
`/now/table/${tableName}/${id}`,
);
responseData = { success: true };
} else if (operation === 'get') {
const tableName = this.getNodeParameter('tableName', i) as string;
const id = this.getNodeParameter('id', i) as string;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -767,11 +902,15 @@ export class ServiceNow implements INodeType {
qs.sysparm_fields = (qs.sysparm_fields as string[]).join(',');
}
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/${tableName}/${id}`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/${tableName}/${id}`,
{},
qs,
);
responseData = response.result;
} else if (operation === 'getAll') {
const tableName = this.getNodeParameter('tableName', i) as string;
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -783,28 +922,39 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/${tableName}`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/${tableName}`,
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', `/now/table/${tableName}`, {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
`/now/table/${tableName}`,
{},
qs,
);
}
} else if (operation === 'update') {
const tableName = this.getNodeParameter('tableName', i) as string;
const id = this.getNodeParameter('id', i) as string;
const dataToSend = this.getNodeParameter('dataToSend', i) as string;
let body = {};
if (dataToSend === 'mapInput') {
const inputsToIgnore = (this.getNodeParameter('inputsToIgnore', i) as string).split(',').map(field => field.trim());
const inputsToIgnore = (this.getNodeParameter('inputsToIgnore', i) as string)
.split(',')
.map((field) => field.trim());
body = Object.entries(items[i].json)
.filter(([key]) => !inputsToIgnore.includes(key))
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {});
} else if (dataToSend === 'columns') {
const fieldsToSend = this.getNodeParameter('fieldsToSend', i) as {
field: IDataObject[]
field: IDataObject[];
};
body = fieldsToSend.field.reduce((obj, field) => {
obj[field.column as string] = field.value;
@@ -812,29 +962,40 @@ export class ServiceNow implements INodeType {
}, {});
}
const response = await serviceNowApiRequest.call(this, 'PATCH', `/now/table/${tableName}/${id}`, body);
const response = await serviceNowApiRequest.call(
this,
'PATCH',
`/now/table/${tableName}/${id}`,
body,
);
responseData = response.result;
} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not known!`,
{ itemIndex: i },
);
}
} else if (resource === 'user') {
if (operation === 'create') {
const body = this.getNodeParameter('additionalFields', i) as IDataObject;
const response = await serviceNowApiRequest.call(this, 'POST', '/now/table/sys_user', body);
const response = await serviceNowApiRequest.call(
this,
'POST',
'/now/table/sys_user',
body,
);
responseData = response.result;
} else if (operation === 'delete') {
const id = this.getNodeParameter('id', i) as string;
responseData = await serviceNowApiRequest.call(this, 'DELETE', `/now/table/sys_user/${id}`);
responseData = await serviceNowApiRequest.call(
this,
'DELETE',
`/now/table/sys_user/${id}`,
);
responseData = { success: true };
} else if (operation === 'get') {
const getOption = this.getNodeParameter('getOption', i) as string;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -844,18 +1005,28 @@ export class ServiceNow implements INodeType {
if (getOption === 'id') {
const id = this.getNodeParameter('id', i) as string;
const response = await serviceNowApiRequest.call(this, 'GET', `/now/table/sys_user/${id}`, {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
`/now/table/sys_user/${id}`,
{},
qs,
);
responseData = response.result;
} else {
const userName = this.getNodeParameter('user_name', i) as string;
qs.sysparm_query = `user_name=${userName}`;
qs.sysparm_limit = 1;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/sys_user', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/sys_user',
{},
qs,
);
responseData = response.result;
}
} else if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -866,26 +1037,43 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/sys_user', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/sys_user',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user',
{},
qs,
);
}
} else if (operation === 'update') {
const id = this.getNodeParameter('id', i) as string;
const body = this.getNodeParameter('updateFields', i) as IDataObject;
const response = await serviceNowApiRequest.call(this, 'PATCH', `/now/table/sys_user/${id}`, body);
const response = await serviceNowApiRequest.call(
this,
'PATCH',
`/now/table/sys_user/${id}`,
body,
);
responseData = response.result;
} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not known!`,
{ itemIndex: i },
);
}
} else if (resource === 'userGroup') {
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -896,17 +1084,32 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/sys_user_group', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/sys_user_group',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user_group', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user_group',
{},
qs,
);
}
} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not known!`,
{ itemIndex: i },
);
}
} else if (resource === 'userRole') {
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
qs = this.getNodeParameter('options', i) as IDataObject;
@@ -917,16 +1120,34 @@ export class ServiceNow implements INodeType {
if (!returnAll) {
const limit = this.getNodeParameter('limit', i) as number;
qs.sysparm_limit = limit;
const response = await serviceNowApiRequest.call(this, 'GET', '/now/table/sys_user_role', {}, qs);
const response = await serviceNowApiRequest.call(
this,
'GET',
'/now/table/sys_user_role',
{},
qs,
);
responseData = response.result;
} else {
responseData = await serviceNowRequestAllItems.call(this, 'GET', '/now/table/sys_user_role', {}, qs);
responseData = await serviceNowRequestAllItems.call(
this,
'GET',
'/now/table/sys_user_role',
{},
qs,
);
}
} else {
throw new NodeOperationError(this.getNode(), `The operation "${operation}" is not known!`, { itemIndex: i });
throw new NodeOperationError(
this.getNode(),
`The operation "${operation}" is not known!`,
{ itemIndex: i },
);
}
} else {
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`, { itemIndex: i });
throw new NodeOperationError(this.getNode(), `The resource "${resource}" is not known!`, {
itemIndex: i,
});
}
} catch (error) {
if (this.continueOnFail()) {