Minor improvements to Contentful-Node

This commit is contained in:
Jan Oberhauser 2020-08-28 17:37:39 +02:00
parent 322b94255a
commit 9be3b97cc3
4 changed files with 25 additions and 65 deletions

View file

@ -192,26 +192,6 @@ export const fields = [
default: '',
description: ' Full-text search is case insensitive and might return more results than expected. A query will only take values with more than 1 character.',
},
],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Select Option',
default: {},
displayOptions: {
show: {
resource: [
resource.value,
],
operation: [
'getAll',
'get'
],
},
},
options: [
{
displayName: 'RAW Data',
name: 'rawData',

View file

@ -67,10 +67,10 @@ export const fields = [
},
},
{
displayName: 'Options',
name: 'options',
displayName: 'Additional Fields',
name: 'additionalFields',
type: 'collection',
placeholder: 'Select Option',
placeholder: 'Add Field',
default: {},
displayOptions: {
show: {

View file

@ -118,11 +118,11 @@ export class Contentful implements INodeType {
const id = this.getNodeParameter('contentTypeId', 0) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/content_types/${id}`);
if (!options.rawData) {
if (!additionalFields.rawData) {
responseData = responseData.fields;
}
}
@ -137,11 +137,11 @@ export class Contentful implements INodeType {
const id = this.getNodeParameter('entryId', 0) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries/${id}`, {}, qs);
if (!options.rawData) {
if (!additionalFields.rawData) {
responseData = responseData.fields;
}
@ -151,11 +151,11 @@ export class Contentful implements INodeType {
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const rawData = additionalFields.rawData;
additionalFields.rawData = undefined;
const env = this.getNodeParameter('environmentId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
Object.assign(qs, additionalFields);
if (qs.equal) {
@ -185,7 +185,7 @@ export class Contentful implements INodeType {
if (returnAll) {
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs);
if (!options.rawData) {
if (!rawData) {
const assets : IDataObject[] = [];
// tslint:disable-next-line: no-any
responseData.map((asset : any) => {
@ -199,7 +199,7 @@ export class Contentful implements INodeType {
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/entries`, {}, qs);
responseData = responseData.items;
if (!options.rawData) {
if (!rawData) {
const assets : IDataObject[] = [];
// tslint:disable-next-line: no-any
responseData.map((asset : any) => {
@ -219,11 +219,11 @@ export class Contentful implements INodeType {
const id = this.getNodeParameter('assetId', 0) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets/${id}`, {}, qs);
if (!options.rawData) {
if (!additionalFields.rawData) {
responseData = responseData.fields;
}
@ -234,11 +234,11 @@ export class Contentful implements INodeType {
const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
const rawData = additionalFields.rawData;
additionalFields.rawData = undefined;
const env = this.getNodeParameter('environmentId', i) as string;
const options = this.getNodeParameter('options', i) as IDataObject;
Object.assign(qs, additionalFields);
if (qs.equal) {
@ -268,7 +268,7 @@ export class Contentful implements INodeType {
if (returnAll) {
responseData = await contenfulApiRequestAllItems.call(this, 'items', 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs);
if (!options.rawData) {
if (!rawData) {
const assets : IDataObject[] = [];
// tslint:disable-next-line: no-any
responseData.map((asset : any) => {
@ -277,12 +277,12 @@ export class Contentful implements INodeType {
responseData = assets;
}
} else {
const limit = this.getNodeParameter('limit', 0) as number;
const limit = this.getNodeParameter('limit', i) as number;
qs.limit = limit;
responseData = await contentfulApiRequest.call(this, 'GET', `/spaces/${credentials?.spaceId}/environments/${env}/assets`, {}, qs);
responseData = responseData.items;
if (!options.rawData) {
if (!rawData) {
const assets : IDataObject[] = [];
// tslint:disable-next-line: no-any
responseData.map((asset : any) => {

View file

@ -182,6 +182,13 @@ export const fields = [
default: '',
description: ' Full-text search is case insensitive and might return more results than expected. A query will only take values with more than 1 character.',
},
{
displayName: 'RAW Data',
name: 'rawData',
type: 'boolean',
default: false,
description: 'If the data should be returned RAW instead of parsed.',
},
],
},
{
@ -201,31 +208,4 @@ export const fields = [
},
},
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Select Option',
default: {},
displayOptions: {
show: {
resource: [
resource.value,
],
operation: [
'get',
'getAll',
],
},
},
options: [
{
displayName: 'RAW Data',
name: 'rawData',
type: 'boolean',
default: false,
description: 'If the data should be returned RAW instead of parsed.',
},
],
},
] as INodeProperties[];