Refactoring

This commit is contained in:
Valentina Lilova 2022-05-20 00:58:23 +03:00
commit 6c337cfb6e
2 changed files with 12 additions and 18 deletions

View file

@ -1,11 +1,8 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import { import {
ICredentialsDecrypted, ICredentialsDecrypted,
ICredentialTestFunctions, ICredentialTestFunctions,
IDataObject, IDataObject,
IExecuteFunctions,
INodeCredentialTestResult, INodeCredentialTestResult,
INodeExecutionData, INodeExecutionData,
INodeType, INodeType,
@ -93,7 +90,8 @@ export class FriendGrid implements INodeType {
message: `${response.error}`, message: `${response.error}`,
}; };
} }
} catch (err) { // tslint:disable-next-line:no-any
} catch (err: any) {
return { return {
status: 'Error', status: 'Error',
message: `${err.message}`, message: `${err.message}`,
@ -115,7 +113,7 @@ export class FriendGrid implements INodeType {
const resource = this.getNodeParameter('resource', 0) as string; const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string; const operation = this.getNodeParameter('operation', 0) as string;
let body: IDataObject = {}; let body: IDataObject = {};
const qs: IDataObject = {}; const qs: IDataObject = {}; // query string
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
try { try {
@ -124,12 +122,9 @@ export class FriendGrid implements INodeType {
// https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact // https://docs.sendgrid.com/api-reference/contacts/add-or-update-a-contact
const email = this.getNodeParameter('email', i) as string; const email = this.getNodeParameter('email', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const data: IDataObject = {
email,
};
const data: IDataObject = { email };
Object.assign(data, additionalFields); Object.assign(data, additionalFields);
body = { body = {
@ -147,7 +142,8 @@ export class FriendGrid implements INodeType {
} else if (responseData !== undefined) { } else if (responseData !== undefined) {
returnData.push(responseData as IDataObject); returnData.push(responseData as IDataObject);
} }
} catch (error) { // tslint:disable-next-line:no-any
} catch (error: any) {
if (this.continueOnFail()) { if (this.continueOnFail()) {
returnData.push({ error: error.message }); returnData.push({ error: error.message });
continue; continue;

View file

@ -3,14 +3,11 @@ import {
} from 'request'; } from 'request';
import { import {
IDataObject,
IExecuteFunctions, IExecuteFunctions,
IExecuteSingleFunctions, IExecuteSingleFunctions,
IHookFunctions, IHookFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
} from 'n8n-core';
import {
IDataObject,
NodeApiError, NodeApiError,
NodeOperationError, NodeOperationError,
} from 'n8n-workflow'; } from 'n8n-workflow';
@ -29,7 +26,7 @@ export async function friendGridApiRequest(this: IHookFunctions | IExecuteFuncti
const options: OptionsWithUri = { const options: OptionsWithUri = {
method, method,
headers: { headers: {
'Accept': ' application/json', 'Accept': 'application/json',
'Authorization': `Bearer ${credentials.apiKey}`, 'Authorization': `Bearer ${credentials.apiKey}`,
}, },
qs, qs,
@ -47,7 +44,8 @@ export async function friendGridApiRequest(this: IHookFunctions | IExecuteFuncti
try { try {
return this.helpers.request!(options); return this.helpers.request!(options);
} catch (error) { // tslint:disable-next-line:no-any
} catch (error: any) {
throw new NodeApiError(this.getNode(), error); throw new NodeApiError(this.getNode(), error);
} }
} }