mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
n8n-3867-progressively-apply-prettier-to-all (#3873)
* 🔨 formatting nodes with prettier
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import {
|
||||
IExecuteFunctions,
|
||||
} from 'n8n-core';
|
||||
import { IExecuteFunctions } from 'n8n-core';
|
||||
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
import { OptionsWithUri } from 'request';
|
||||
|
||||
import {
|
||||
ICredentialsDecrypted,
|
||||
@@ -24,10 +20,7 @@ import {
|
||||
validateJSON,
|
||||
} from './GenericFunctions';
|
||||
|
||||
import {
|
||||
entryFields,
|
||||
entryOperations,
|
||||
} from './EntryDescription';
|
||||
import { entryFields, entryOperations } from './EntryDescription';
|
||||
|
||||
export class Strapi implements INodeType {
|
||||
description: INodeTypeDescription = {
|
||||
@@ -71,8 +64,11 @@ export class Strapi implements INodeType {
|
||||
|
||||
methods = {
|
||||
credentialTest: {
|
||||
async strapiApiTest(this: ICredentialTestFunctions, credential: ICredentialsDecrypted): Promise<INodeCredentialTestResult> {
|
||||
const credentials = await credential.data as IDataObject;
|
||||
async strapiApiTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = (await credential.data) as IDataObject;
|
||||
let options = {} as OptionsWithUri;
|
||||
|
||||
options = {
|
||||
@@ -84,21 +80,24 @@ export class Strapi implements INodeType {
|
||||
identifier: credentials.email,
|
||||
password: credentials.password,
|
||||
},
|
||||
uri: credentials.apiVersion === 'v4' ? `${credentials.url}/api/auth/local`:`${credentials.url}/auth/local`,
|
||||
uri:
|
||||
credentials.apiVersion === 'v4'
|
||||
? `${credentials.url}/api/auth/local`
|
||||
: `${credentials.url}/auth/local`,
|
||||
json: true,
|
||||
};
|
||||
try {
|
||||
await this.helpers.request(options);
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Authentication successful',
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: `Auth settings are not valid: ${error}`,
|
||||
};
|
||||
}
|
||||
try {
|
||||
await this.helpers.request(options);
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Authentication successful',
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: `Auth settings are not valid: ${error}`,
|
||||
};
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -121,21 +120,30 @@ export class Strapi implements INodeType {
|
||||
try {
|
||||
if (resource === 'entry') {
|
||||
if (operation === 'create') {
|
||||
|
||||
const body: IDataObject = {};
|
||||
|
||||
const contentType = this.getNodeParameter('contentType', i) as string;
|
||||
|
||||
const columns = this.getNodeParameter('columns', i) as string;
|
||||
|
||||
const columnList = columns.split(',').map(column => column.trim());
|
||||
const columnList = columns.split(',').map((column) => column.trim());
|
||||
|
||||
for (const key of Object.keys(items[i].json)) {
|
||||
if (columnList.includes(key)) {
|
||||
apiVersion === 'v4'? body.data = items[i].json: body[key] = items[i].json[key];
|
||||
apiVersion === 'v4'
|
||||
? (body.data = items[i].json)
|
||||
: (body[key] = items[i].json[key]);
|
||||
}
|
||||
}
|
||||
responseData = await strapiApiRequest.call(this, 'POST', `/${contentType}`, body, qs, undefined, headers);
|
||||
responseData = await strapiApiRequest.call(
|
||||
this,
|
||||
'POST',
|
||||
`/${contentType}`,
|
||||
body,
|
||||
qs,
|
||||
undefined,
|
||||
headers,
|
||||
);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
@@ -145,13 +153,20 @@ export class Strapi implements INodeType {
|
||||
|
||||
const entryId = this.getNodeParameter('entryId', i) as string;
|
||||
|
||||
responseData = await strapiApiRequest.call(this, 'DELETE', `/${contentType}/${entryId}`, {}, qs, undefined, headers);
|
||||
responseData = await strapiApiRequest.call(
|
||||
this,
|
||||
'DELETE',
|
||||
`/${contentType}/${entryId}`,
|
||||
{},
|
||||
qs,
|
||||
undefined,
|
||||
headers,
|
||||
);
|
||||
|
||||
returnData.push(responseData);
|
||||
}
|
||||
|
||||
if (operation === 'getAll') {
|
||||
|
||||
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
|
||||
|
||||
const contentType = this.getNodeParameter('contentType', i) as string;
|
||||
@@ -170,7 +185,9 @@ export class Strapi implements INodeType {
|
||||
if (query !== undefined) {
|
||||
qs.filters = query;
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Query must be a valid JSON', { itemIndex: i });
|
||||
throw new NodeOperationError(this.getNode(), 'Query must be a valid JSON', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
}
|
||||
// Publication Option
|
||||
@@ -179,10 +196,25 @@ export class Strapi implements INodeType {
|
||||
}
|
||||
// Limit Option
|
||||
if (returnAll) {
|
||||
responseData = await strapiApiRequestAllItems.call(this, 'GET', `/${contentType}`, {}, qs, headers);
|
||||
responseData = await strapiApiRequestAllItems.call(
|
||||
this,
|
||||
'GET',
|
||||
`/${contentType}`,
|
||||
{},
|
||||
qs,
|
||||
headers,
|
||||
);
|
||||
} else {
|
||||
qs['pagination[pageSize]'] = this.getNodeParameter('limit', i) as number;
|
||||
({ data:responseData } = await strapiApiRequest.call(this, 'GET', `/${contentType}`, {}, qs, undefined, headers));
|
||||
({ data: responseData } = await strapiApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/${contentType}`,
|
||||
{},
|
||||
qs,
|
||||
undefined,
|
||||
headers,
|
||||
));
|
||||
}
|
||||
} else {
|
||||
// Sort Option
|
||||
@@ -196,7 +228,9 @@ export class Strapi implements INodeType {
|
||||
if (query !== undefined) {
|
||||
qs._where = query;
|
||||
} else {
|
||||
throw new NodeOperationError(this.getNode(), 'Query must be a valid JSON', { itemIndex: i });
|
||||
throw new NodeOperationError(this.getNode(), 'Query must be a valid JSON', {
|
||||
itemIndex: i,
|
||||
});
|
||||
}
|
||||
}
|
||||
// Publication Option
|
||||
@@ -205,27 +239,50 @@ export class Strapi implements INodeType {
|
||||
}
|
||||
// Limit Option
|
||||
if (returnAll) {
|
||||
responseData = await strapiApiRequestAllItems.call(this, 'GET', `/${contentType}`, {}, qs, headers);
|
||||
responseData = await strapiApiRequestAllItems.call(
|
||||
this,
|
||||
'GET',
|
||||
`/${contentType}`,
|
||||
{},
|
||||
qs,
|
||||
headers,
|
||||
);
|
||||
} else {
|
||||
qs._limit = this.getNodeParameter('limit', i) as number;
|
||||
responseData = await strapiApiRequest.call(this, 'GET', `/${contentType}`, {}, qs, undefined, headers);
|
||||
responseData = await strapiApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/${contentType}`,
|
||||
{},
|
||||
qs,
|
||||
undefined,
|
||||
headers,
|
||||
);
|
||||
}
|
||||
}
|
||||
returnData.push.apply(returnData, responseData);
|
||||
}
|
||||
|
||||
if (operation === 'get') {
|
||||
|
||||
const contentType = this.getNodeParameter('contentType', i) as string;
|
||||
|
||||
const entryId = this.getNodeParameter('entryId', i) as string;
|
||||
|
||||
responseData = await strapiApiRequest.call(this, 'GET', `/${contentType}/${entryId}`, {}, qs, undefined, headers);
|
||||
apiVersion === 'v4'? returnData.push(responseData.data): returnData.push(responseData);
|
||||
responseData = await strapiApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
`/${contentType}/${entryId}`,
|
||||
{},
|
||||
qs,
|
||||
undefined,
|
||||
headers,
|
||||
);
|
||||
apiVersion === 'v4'
|
||||
? returnData.push(responseData.data)
|
||||
: returnData.push(responseData);
|
||||
}
|
||||
|
||||
if (operation === 'update') {
|
||||
|
||||
const body: IDataObject = {};
|
||||
|
||||
const contentType = this.getNodeParameter('contentType', i) as string;
|
||||
@@ -234,19 +291,30 @@ export class Strapi implements INodeType {
|
||||
|
||||
const updateKey = this.getNodeParameter('updateKey', i) as string;
|
||||
|
||||
const columnList = columns.split(',').map(column => column.trim());
|
||||
const columnList = columns.split(',').map((column) => column.trim());
|
||||
|
||||
const entryId = items[i].json[updateKey];
|
||||
|
||||
for (const key of Object.keys(items[i].json)) {
|
||||
if (columnList.includes(key)) {
|
||||
apiVersion === 'v4'? body.data = items[i].json:body[key] = items[i].json[key];
|
||||
apiVersion === 'v4'
|
||||
? (body.data = items[i].json)
|
||||
: (body[key] = items[i].json[key]);
|
||||
}
|
||||
}
|
||||
|
||||
responseData = await strapiApiRequest.call(this, 'PUT', `/${contentType}/${entryId}`, body, qs, undefined, headers);
|
||||
apiVersion === 'v4'? returnData.push(responseData.data): returnData.push(responseData);
|
||||
|
||||
responseData = await strapiApiRequest.call(
|
||||
this,
|
||||
'PUT',
|
||||
`/${contentType}/${entryId}`,
|
||||
body,
|
||||
qs,
|
||||
undefined,
|
||||
headers,
|
||||
);
|
||||
apiVersion === 'v4'
|
||||
? returnData.push(responseData.data)
|
||||
: returnData.push(responseData);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user